From patchwork Thu Feb 22 23:16:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 158CAC47DD9 for ; Thu, 22 Feb 2024 23:16:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99C596B007D; Thu, 22 Feb 2024 18:16:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 88A906B0083; Thu, 22 Feb 2024 18:16:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55C5C6B007E; Thu, 22 Feb 2024 18:16:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3DF316B007D for ; Thu, 22 Feb 2024 18:16:40 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B1371A0E7C for ; Thu, 22 Feb 2024 23:16:39 +0000 (UTC) X-FDA: 81821001318.16.504273B Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf06.hostedemail.com (Postfix) with ESMTP id AC02818001B for ; Thu, 22 Feb 2024 23:16:36 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=pEK+4GzJ; spf=pass (imf06.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643796; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v5Cp82ySxfsN2PrtsAgumsLlaAyDJCQKtLBCPd8HpWo=; b=jEKDrK8B4CS6qcHkE5W6+VsQP3RKqzUkKP/K0PnJ5tJPjZ9gGbBtbWX84w+4L3wUggDA5Q P1JdpFc2IVxPnSQi2qMaE0nG76Elk6Lk75zQvFPU5+/jvlAUlBc5xxWKaErM/80zg3/kqN yRT4U40s0DmtplI/HELRvymiRnU3hqQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643796; a=rsa-sha256; cv=none; b=5zJPOUdbetZi4TL9Nhh1Q0BuJV/2+o1rzZFfmPUXVY+9m93n/Y4JJnvoELrT3eZRiicyWU GvPTobW0B+0SkR9AgCCV5hJQ3i3xH84yuiEYgYVv66NYhrAW8R7Ovm41QYT47QKHWX4+Ym ZSUSnmNYs5ZK38yWICPXyX+pxpfDSmc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=pEK+4GzJ; spf=pass (imf06.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMsXqN014811; Thu, 22 Feb 2024 23:16:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=v5Cp82ySxfsN2PrtsAgumsLlaAyDJCQKtLBCPd8HpWo =; b=pEK+4GzJjBQCK1sErKzRh7OLQuAogVY+p6WN4Km6+u75gRxEx9UJM4qNrLk 5/8AqGxnHg7SSj9OdW7OtHLMoN6rESW8+Z89ZGEwySnq5Qv5FSTIBfEYnLD0zekY t7Au7W153WR1tasbqCYD7mt8YJj9ugVT8nD13JWj2DKzGiLsqDFTXKDV23q9slCO fpIvOZEHVH2jd0ISgHEkO+d7SE719bZImnmg6UNeUZmCJY954DGCfloL8Vgd/pe9 ApoPCT5tCImClxpisa6El0tXqHpQPQ+epAaW8xz/sSZIcWQJnt3UUSwMitHW/QrX YITsFwLPbBZFCfUp+u92W9PJJ8g== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wdw13afve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:29 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGROA027655 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:28 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:27 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:24 -0800 Subject: [PATCH v17 01/35] docs: gunyah: Introduce Gunyah Hypervisor MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-1-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: BmKGDWF2HL3902ISFPTZtRcFZK3Q9KrT X-Proofpoint-GUID: BmKGDWF2HL3902ISFPTZtRcFZK3Q9KrT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 malwarescore=0 impostorscore=0 bulkscore=0 adultscore=0 mlxscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 priorityscore=1501 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: AC02818001B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 8m1379kq7kjughww7osqihop1pbukq4s X-HE-Tag: 1708643796-546855 X-HE-Meta: U2FsdGVkX188+pjRnezdDFNZsf1Y0dCVbG/BQr6mz2Z0fa2yAgeI1PXVDW82YohGwpi34S/2W3D3Sfnj7s924Mnxjaiq3g985xpjBjyuAfIoigQfjcxEKovdcl5GTTuyLLTPHkwP/oAb7C4aeHFJfKx9e0ElfLFSwydvqQ2c0tmI922Nw89s//JXHjZzN6BfC0xEDmecSNmkQvdpVIHr4wG80kK9f/A/Sts57FOw+yuL5BCRGV2kWtLbksidSx3vQcKMO6LOleJ3pLMiJh/5OtWRmDQBg1Dd12re+VbNW2nAQR0uVbDexZ0d1ooD+ruonVqKpTmpseACd3PHJ2/uiX8PMZTkzQAVLuDMwyA167gueAwtLf4pW6q/HADHdtMHAiSpcyDN4e9AOLxm4TKEGv746Jd9xFoxyNxON2W0UKweG8++k2CU6QxhcgQk/nt1T43sCA3+6KGN4obuX+4PYZ+h9t8lUH43num9Q6cix0DoLKn/45bcbZBdHAvhiI9gfm1RWYXhtItirBl/D80AXQbbR6Mq3piDsWqcgTUlaRcE+K1yYSyykkVfZtYP6swAQXUDtHAfHZWruqfttgrSuHa9z+vc+ew1LFwJiKfHGygMTUrZXoDX/Hb4moY4kcmpdaF2A/y3PrCW/owNiDWjBqHvEHAh9lcPlRQKBnX3RX1FULnkIk2G6zv65EyuVUxY0gVboaXyt0esJIlPQ0juWFMbHNQsELrqJH4yxnHA4URoM47aZM65P6x6RKoc2dFy5gfgQXsuol9J+b9SygQ6I/Hgb4PULKrd/dae3kjdX1qT6RiYx0qCvbSFM1grJBgU5m90+V7MdtVtwMHOFNMgdCH+mgDe2dHXdClYJg4SirOrql91uhfdTIBnq8+lPl8LpSsuy7dP3iblqhBsI2ORJV0K6kW3PZ+koufuNx7yL+JQQPdKmiOAYKwEWvpWPkibJCml9wRnTz4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Gunyah is an open-source Type-1 hypervisor developed by Qualcomm. It does not depend on any lower-privileged OS/kernel code for its core functionality. This increases its security and can support a smaller trusted computing based when compared to Type-2 hypervisors. Add documentation describing the Gunyah hypervisor and the main components of the Gunyah hypervisor which are of interest to Linux virtualization development. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- Documentation/virt/gunyah/index.rst | 135 ++++++++++++++++++++++++++++ Documentation/virt/gunyah/message-queue.rst | 68 ++++++++++++++ Documentation/virt/index.rst | 1 + 3 files changed, 204 insertions(+) diff --git a/Documentation/virt/gunyah/index.rst b/Documentation/virt/gunyah/index.rst new file mode 100644 index 0000000000000..fba2c7a11d0f8 --- /dev/null +++ b/Documentation/virt/gunyah/index.rst @@ -0,0 +1,135 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +Gunyah Hypervisor +================= + +.. toctree:: + :maxdepth: 1 + + message-queue + +Gunyah is a Type-1 hypervisor which is independent of any OS kernel, and runs in +a more privileged CPU level (EL2 on Aarch64). It does not depend on a less +privileged operating system for its core functionality. This increases its +security and can support a much smaller trusted computing base than a Type-2 +hypervisor. + +Gunyah is an open source hypervisor. The source repository is available at +https://github.com/quic/gunyah-hypervisor. + +Gunyah provides these following features. + +- Scheduling: + + A scheduler for virtual CPUs (vCPUs) on physical CPUs enables time-sharing + of the CPUs. Gunyah supports two models of scheduling which can coexist on + a running system: + + 1. Hypervisor vCPU scheduling in which Gunyah hypervisor schedules vCPUS on + its own. The default is a real-time priority with round-robin scheduler. + 2. "Proxy" scheduling in which an owner-VM can donate the remainder of its + own vCPU's time slice to an owned-VM's vCPU via a hypercall. + +- Memory Management: + + APIs handling memory, abstracted as objects, limiting direct use of physical + addresses. Memory ownership and usage tracking of all memory under its control. + Memory partitioning between VMs is a fundamental security feature. + +- Interrupt Virtualization: + + Interrupt ownership is tracked and interrupt delivery is directly to the + assigned VM. Gunyah makes use of hardware interrupt virtualization where + possible. + +- Inter-VM Communication: + + There are several different mechanisms provided for communicating between VMs. + + 1. Message queues + 2. Doorbells + 3. Virtio MMIO transport + 4. Shared memory + +- Virtual platform: + + Architectural devices such as interrupt controllers and CPU timers are + directly provided by the hypervisor as well as core virtual platform devices + and system APIs such as ARM PSCI. + +- Device Virtualization: + + Para-virtualization of devices is supported using inter-VM communication and + virtio transport support. Select stage 2 faults by virtual machines that use + proxy-scheduled vCPUs can be handled directly by Linux to provide Type-2 + hypervisor style on-demand paging and/or device emulation. + +Architectures supported +======================= +AArch64 with a GICv3 or GICv4.1 + +Resources and Capabilities +========================== + +Services/resources provided by the Gunyah hypervisor are accessible to a +virtual machine through capabilities. A capability is an access control +token granting the holder a set of permissions to operate on a specific +hypervisor object (conceptually similar to a file-descriptor). +For example, inter-VM communication using Gunyah doorbells and message queues +is performed using hypercalls taking Capability ID arguments for the required +IPC objects. These resources are described in Linux as a struct gunyah_resource. + +Unlike UNIX file descriptors, there is no path-based or similar lookup of +an object to create a new Capability, meaning simpler security analysis. +Creation of a new Capability requires the holding of a set of privileged +Capabilities which are typically never given out by the Resource Manager (RM). + +Gunyah itself provides no APIs for Capability ID discovery. Enumeration of +Capability IDs is provided by RM as a higher level service to VMs. + +Resource Manager +================ + +The Gunyah Resource Manager (RM) is a privileged application VM supporting the +Gunyah Hypervisor. It provides policy enforcement aspects of the virtualization +system. The resource manager can be treated as an extension of the Hypervisor +but is separated to its own partition to ensure that the hypervisor layer itself +remains small and secure and to maintain a separation of policy and mechanism in +the platform. The resource manager runs at arm64 NS-EL1, similar to other +virtual machines. + +Communication with the resource manager from other virtual machines happens as +described in message-queue.rst. Details about the specific messages can be found +in drivers/virt/gunyah/rsc_mgr.c + +:: + + +-------+ +--------+ +--------+ + | RM | | VM_A | | VM_B | + +-.-.-.-+ +---.----+ +---.----+ + | | | | + +-.-.-----------.------------.----+ + | | \==========/ | | + | \========================/ | + | Gunyah | + +---------------------------------+ + +The source for the resource manager is available at +https://github.com/quic/gunyah-resource-manager. + +The resource manager provides the following features: + +- VM lifecycle management: allocating a VM, starting VMs, destruction of VMs +- VM access control policy, including memory sharing and lending +- Interrupt routing configuration +- Forwarding of system-level events (e.g. VM shutdown) to owner VM +- Resource (capability) discovery + +A VM requires boot configuration to establish communication with the resource +manager. This is provided to VMs via a 'hypervisor' device tree node which is +overlaid to the VMs DT by the RM. This node lets guests know they are running +as a Gunyah guest VM, how to communicate with resource manager, and basic +description and capabilities of this VM. See +Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml for a +description of this node. diff --git a/Documentation/virt/gunyah/message-queue.rst b/Documentation/virt/gunyah/message-queue.rst new file mode 100644 index 0000000000000..96864708f442e --- /dev/null +++ b/Documentation/virt/gunyah/message-queue.rst @@ -0,0 +1,68 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Message Queues +============== +Message queue is a simple low-capacity IPC channel between two virtual machines. +It is intended for sending small control and configuration messages. Each +message queue is unidirectional and buffered in the hypervisor. A full-duplex +IPC channel requires a pair of queues. + +The size of the queue and the maximum size of the message that can be passed is +fixed at creation of the message queue. Resource manager is presently the only +use case for message queues, and creates messages queues between itself and VMs +with a fixed maximum message size of 240 bytes. Longer messages require a +further protocol on top of the message queue messages themselves. For instance, +communication with the resource manager adds a header field for sending longer +messages which are split into smaller fragments. + +The diagram below shows how message queue works. A typical configuration +involves 2 message queues. Message queue 1 allows VM_A to send messages to VM_B. +Message queue 2 allows VM_B to send messages to VM_A. + +1. VM_A sends a message of up to 240 bytes in length. It makes a hypercall + with the message to request the hypervisor to add the message to + message queue 1's queue. The hypervisor copies memory into the internal + message queue buffer; the memory doesn't need to be shared between + VM_A and VM_B. + +2. Gunyah raises the corresponding interrupt for VM_B (Rx vIRQ) when any of + these happens: + + a. gunyah_msgq_send() has PUSH flag. This is a typical case when the message + queue is being used to implement an RPC-like interface. + b. Explicitly with gunyah_msgq_push hypercall from VM_A. + c. Message queue has reached a threshold depth. Typically, this threshold + depth is the size of the queue (in other words: when queue is full, Rx + vIRQ is raised). + +3. VM_B calls gunyah_msgq_recv() and Gunyah copies message to requested buffer. + +4. Gunyah raises the corresponding interrupt for VM_A (Tx vIRQ) when the message + queue falls below a watermark depth. Typically, this is when the queue is + drained. Note the watermark depth and the threshold depth for the Rx vIRQ are + independent values. Coincidentally, this signal is conceptually similar to + Clear-to-Send. + +For VM_B to send a message to VM_A, the process is identical, except that +hypercalls reference message queue 2's capability ID. The IRQ will be different +for the second message queue. + +:: + + +-------------------+ +-----------------+ +-------------------+ + | VM_A | |Gunyah hypervisor| | VM_B | + | | | | | | + | | | | | | + | | Tx | | | | + | |-------->| | Rx vIRQ | | + |gunyah_msgq_send() | Tx vIRQ |Message queue 1 |-------->|gunyah_msgq_recv() | + | |<------- | | | | + | | | | | | + | | | | | | + | | | | Tx | | + | | Rx vIRQ | |<--------| | + |gunyah_msgq_recv() |<--------|Message queue 2 | Tx vIRQ |gunyah_msgq_send() | + | | | |-------->| | + | | | | | | + | | | | | | + +-------------------+ +-----------------+ +---------------+ diff --git a/Documentation/virt/index.rst b/Documentation/virt/index.rst index 7fb55ae08598d..15869ee059b35 100644 --- a/Documentation/virt/index.rst +++ b/Documentation/virt/index.rst @@ -16,6 +16,7 @@ Virtualization Support coco/sev-guest coco/tdx-guest hyperv/index + gunyah/index .. only:: html and subproject From patchwork Thu Feb 22 23:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2FB0C47DD9 for ; Thu, 22 Feb 2024 23:16:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C03E6B0083; Thu, 22 Feb 2024 18:16:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FE866B0088; Thu, 22 Feb 2024 18:16:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EC226B0085; Thu, 22 Feb 2024 18:16:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F08766B0082 for ; Thu, 22 Feb 2024 18:16:41 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CC1E940FB9 for ; Thu, 22 Feb 2024 23:16:41 +0000 (UTC) X-FDA: 81821001402.26.1028D89 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf02.hostedemail.com (Postfix) with ESMTP id B07468000D for ; Thu, 22 Feb 2024 23:16:39 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=jpuNQvcn; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf02.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643799; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oWnghs7sEsHkez39tQquVTv8CCRTmJHz664b/mA4aIY=; b=h+XKXypD5bd+RWjub2Hfp+RXg85YfhvdBvq7gmMZLB/H9FuBmmRU9VZYiiNvnkP65mTLqq M7BZhXjaGRVw/QcfiPktyL9Wg0B4Eam8Tc6iHJ7NsypEquvvjqB/Sumom6dwyLoF69ANcF HuZX3DODyycRHkuIdsfxgSm9hCI+Hl0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=jpuNQvcn; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf02.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643799; a=rsa-sha256; cv=none; b=i7IczvyhFkZMOTzWWXot3UCYuq1jsoxLpoRvrDAuLoT07kHCQqXAiiiX1wZXeCQjP2pbpO xyJJnQUZ4OPcOCz74mG7uJPM4okJa7Y2lE/J2hg0ffeTutl6F6UUqaut6R8kxshtyiN/Yi bMgXXF1PlHnyl6pNO9R14fFwSWwkgD0= Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLm2Yd008649; Thu, 22 Feb 2024 23:16:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=oWnghs7sEsHkez39tQquVTv8CCRTmJHz664b/mA4aIY =; b=jpuNQvcnyJPwtVHp8e4pknykV3AH0Tq+yWjN+KZYz2iTOLpEOQ0QfV7wK9w U4AyUZce+Z8u/xR0LXfb4x2fASPNWSyomWv+txCrJr3mh8A8YVX5+Atk30WkvGKo bnC9nC85oV/2MdEguoI24gZ2Vfuzp6c2nOciqqp39wW8Mj1tqjdOwBLjc2aTZtL3 0SemDeNxUTWzxwwwnViXfKmpTmikWsTpxldC379ttWND9mSvdjbje3PISsaHDM55 L2y+hpsCkSjly9x3QQd/VTdUGMFf5PVhUJoBiHMT0xMDnRO+f+DpL/JalTXfVCgF 36IQg4UnCpXkb8c8o48UvwkbDVA== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wdw13afvf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:29 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGS2D017417 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:28 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:27 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:25 -0800 Subject: [PATCH v17 02/35] dt-bindings: Add binding for gunyah hypervisor MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-2-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman , Rob Herring X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: B4jDgrHxuxRwopWHvIyZDMwv1ZmQ6FLi X-Proofpoint-GUID: B4jDgrHxuxRwopWHvIyZDMwv1ZmQ6FLi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 malwarescore=0 impostorscore=0 bulkscore=0 adultscore=0 mlxscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 priorityscore=1501 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B07468000D X-Stat-Signature: zmhfpc7356gmfwfq1u5bbhugp1kppqoc X-HE-Tag: 1708643799-989961 X-HE-Meta: U2FsdGVkX1+GZ4TDPDy/5Gy1KY7468xjRTdPY+XKaguOD8rfX1bttN8594C8n1NCWNmheqnfN2c24KPa7VJpGWtUtrJoacSO/ihW/W/124kTmDE3e6R8WPMQRBrsg8D25hzseQz7dP8426pYt7CcwJvFj7q1HNoT49tZNamSl/zA5hBj3jyv3Qk0vil27RuKByvFhZFgIx1GsGxAxv6TNwhqCLexuzXuXlxe2+Gxjwbkw9GQRU1iCrCQ4lFHu+RrNe/EVKijozlcBxz5DUhc+ZWUmNu1dlbSbVh2s8A+yA+meR39MVU8BKNDu8i945uSV7rC/q9XVUgPxZq2UAJP6VdMGeZyh7KRjrSsQ1wAv6Hi27wCe7U0YD3L3K0ZYMmyrnwsWoDMIjD8ysxeYnk2UAuJtk4dkALnlrvkOODDzBMvDYfDrSS4So5f66eBo5Y+gtVR4fxyBEXIVBABZs2BwI6izmbt7NgGd7f0fPCqlPU/2KLLEK5tAodrtaqy9wLl5O1z9zsDwTfj/tONSU/mkiV2riOxWpu/RSmMk0Tl0lewU1Z2K6F8W/FKifBjqfj4QrutdyuguJCNTbHz1eqSjpFHgBiuK4Lu2SbHxIIXzhoZ1X6DxgiVUO4GphMLHoh0vJyOiki4TQtIMfPMfVfdcHEW8HJBfQnr5DRdEptLmdk0vGIsfjQcEs/QyT2lvrWmlDQErqVxE2Qh2+mAijztZWoxqHqSGP117NQN+32Mha3nf4DkzqkMbkelX08D5u+RWPb8F/KVkfjn0j/ZdbRvjgiNys3oXv9HNssRaj2W1vVWNzr61KrZj87ch5ot4utyfbXerYBlMKj8PvYtIV8rzOXX3L4aI2OF6IotT4EtlGb/gnTvyy3zVDYFKxzd/ErmnII6e4og9oR9EJU9p/vaVgbNkBgaTTUu03TPSgwUem3yFUBSF6RONMbl7EmtuDEHfTvwWTRMj6wmNltA1FX eh31qtN1 7rEgQ0ArGOBnH2iV4vmY+0z0FiQEs3THKZoIuDlUdO0M9d6BalJqqX1YEYdrc30//K34O/h/3T5J1DOlVkZnV5diJqm/ORzOpkgNT+LD6HEdYZoTHkwJVsgHONfwmoDj24/x4XBNu/np9v63qDy60ijsOtenbNrefBocGJVf4LEAhFlXRyhFxrO0Z7FeS3QWB7Yjy6nyU5E4ePZXIL0hHk903SjxMNbipjzJTHwsxpC8aKaC5lQV3lCiB0V3q3qjDg18VKrThbaDco31JRtHR7au07dQv9rDZReUYyzu0ruYRYImcJ3hDoHDgHkMnPE6JLpjutrPeZWaflPT6cAdSY2bxyPQFeNKZSfRCmHdqSK+wllWMUS53tV/3xOZZVFE+Hd3OlWCozw8iUPA2M1yKHRkrMnsHOoB6XpJRSivuGqAls2UHQxfXj6G+xT605xqyzBfTi3Ii3skVbzGfpSkHDtB3GbyjscpQPWNmS3quJCYAhoGUSmhBTpH4POwY2mvTh49dld4qPFgTWpU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The Gunyah Resource Manager applies a devicetree overlay describing the virtual platform configuration of the guest VM, such as the message queue capability IDs for communicating with the Resource Manager. This information is not otherwise discoverable by a VM: the Gunyah hypervisor core does not provide a direct interface to discover capability IDs nor a way to communicate with RM without having already known the corresponding message queue capability ID. Add the DT bindings that Gunyah adheres for the hypervisor node and message queues. Reviewed-by: Rob Herring Signed-off-by: Elliot Berman --- .../bindings/firmware/gunyah-hypervisor.yaml | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml b/Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml new file mode 100644 index 0000000000000..cdeb4885a8072 --- /dev/null +++ b/Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml @@ -0,0 +1,82 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/gunyah-hypervisor.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Gunyah Hypervisor + +maintainers: + - Prakruthi Deepak Heragu + - Elliot Berman + +description: |+ + Gunyah virtual machines use this information to determine the capability IDs + of the message queues used to communicate with the Gunyah Resource Manager. + See also: https://github.com/quic/gunyah-resource-manager/blob/develop/src/vm_creation/dto_construct.c + +properties: + compatible: + const: gunyah-hypervisor + + "#address-cells": + description: Number of cells needed to represent 64-bit capability IDs. + const: 2 + + "#size-cells": + description: must be 0, because capability IDs are not memory address + ranges and do not have a size. + const: 0 + +patternProperties: + "^gunyah-resource-mgr(@.*)?": + type: object + description: + Resource Manager node which is required to communicate to Resource + Manager VM using Gunyah Message Queues. + + properties: + compatible: + const: gunyah-resource-manager + + reg: + items: + - description: Gunyah capability ID of the TX message queue + - description: Gunyah capability ID of the RX message queue + + interrupts: + items: + - description: Interrupt for the TX message queue + - description: Interrupt for the RX message queue + + additionalProperties: false + + required: + - compatible + - reg + - interrupts + +additionalProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +examples: + - | + #include + + hypervisor { + #address-cells = <2>; + #size-cells = <0>; + compatible = "gunyah-hypervisor"; + + gunyah-resource-mgr@0 { + compatible = "gunyah-resource-manager"; + interrupts = , /* TX allowed IRQ */ + ; /* RX requested IRQ */ + reg = <0x00000000 0x00000000>, /* TX capability ID */ + <0x00000000 0x00000001>; /* RX capability ID */ + }; + }; From patchwork Thu Feb 22 23:16:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568224 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BDCEC54E49 for ; Thu, 22 Feb 2024 23:16:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D842C6B007E; Thu, 22 Feb 2024 18:16:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE0456B0081; Thu, 22 Feb 2024 18:16:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 953BF6B0082; Thu, 22 Feb 2024 18:16:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7837B6B0081 for ; Thu, 22 Feb 2024 18:16:40 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 59199160FFA for ; Thu, 22 Feb 2024 23:16:40 +0000 (UTC) X-FDA: 81821001360.08.1174AC5 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf24.hostedemail.com (Postfix) with ESMTP id 40649180010 for ; Thu, 22 Feb 2024 23:16:36 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=X6Vli6+s; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf24.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643797; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eO62myJpAZB3KKFa7P4YEhFwAaiw2pagW6qYX+cFAXk=; b=lMyKa4kTbyb0Y2TqiuFSTnoNjdv0+wFl6igHj3nOAG1nzq5k7YlDkcx2peJMXI8D16buJH fF/T2HHfjpdGEJAnvXg7AWRMhQSRk105vxg7qONDocoXYYMNWsmLVYxgYHIv8hvxrFyJ1D CNialc5k4O+oz6yzlcc7uF9HSwv18Hs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=X6Vli6+s; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf24.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643797; a=rsa-sha256; cv=none; b=0WDju68+1uaj4L0qi92bwAaOgs+/Lffvv+HV9YzFbMO3nJOgaMZJLDg3ql+5gcH1XuAlJN zBlVXbHCMmjlIwJm8yxQsQHdVeQIZlgWJFAKyYuMFr05/M1cGFrf1fYo+/j3RwkaU4HNmS ZFYqZlgk9arSsh1XpVZCDt12TT0f3YE= Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMfwf5023099; Thu, 22 Feb 2024 23:16:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=eO62myJpAZB3KKFa7P4YEhFwAaiw2pagW6qYX+cFAXk =; b=X6Vli6+sDHoLKdCXLHo9rQCyHJ3JHSrcQaJFf4s9JVXZO26TfdnSbBDa6Xy 9rrjk6I87O8PbgsRCmF2O3TjAKBwZH7MJvnS0q3M+zebEACERDRy31bM7M1lNJu6 OC3FMDP9wwWbTUW/1F26tWtu8DRswt/2P3UYA6TMX2WA7ZO1V+H99JM7fSW2dgAJ n/bn58HED8F3AJU89n7ZdGEwE4UuVVvfV8274ztgtslPFvJT5+R/aAUZ0K8d6VB2 G4NSypuelBTlmF0RLBCdvYe4Jpgk7KS1yI1PMfclxIu8XswED/yn9k2YCKZuETxd F7spCEiOpWlCm5AgCiPFQFp4YHw== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wdw13afvh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:29 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGTLY027663 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:29 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:28 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:26 -0800 Subject: [PATCH v17 03/35] gunyah: Common types and error codes for Gunyah hypercalls MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-3-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: nyPv04IQzCqrW0808AZtf8mr0XHoRsna X-Proofpoint-GUID: nyPv04IQzCqrW0808AZtf8mr0XHoRsna X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=482 malwarescore=0 impostorscore=0 bulkscore=0 adultscore=0 mlxscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 priorityscore=1501 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: 40649180010 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: oi6mqcztr9ohpk9zaungaqts9zw9hd6x X-HE-Tag: 1708643796-339435 X-HE-Meta: U2FsdGVkX1+ELneLVmmaoI/veIPCi37AXw99xiPm4mOFKPmgNHmXaXZzIf/Jy8yClpMOCIPb8L7LcoXI4OIQBLMvEwLIc3Ax7iz/s61rlFQOIyC/SA77XwrY9Tu+Gckgkb26XL4sabal5Lm+N1XF+R9RdhKwYjn3iv/fR172C/fulCb5Wr6cQ6DJbtokv5o1LmKebWqI5nKBlueYNAeLfuL46hk5a+pdYQS6yWuEOVF6t5myjMrpaRqHSSRBUVrZTeKNgU1fHAKJNMaWmpV4TTLncNf//01fht1CJBpQ/4+6iYIAsi+VCuCPSB4f3Vp2hQ0GdJF6yMt+P/jb3KTPkBV+IAPzasL6S4LO/dijAgkNi8I0Iko11WkMypY5ay+F4W3xPtlbjDNch8dJH7pUbuPmE/dB62OdcxlMUdmM9xbjFsqx0VBu1pWzERB3WY5odbNLBzDMBp6T86oNfRspufyasVOfgySPQVBrTVse0PgBcnQKonp8Ah2DLI2MV2j2HP1atpo9jsNuE6m+5X5cBaKy1MprWtmpHM6PXLZWwyvt2sEr5h8b5hbpgToqYOpxzc9HCGhhaH0G8ZVOR6mZLl+pIOePp1op37Ulw5d4BmuBgxAnRkxMB58TG+zyI41nnoSVD4rfM+yjn60i0yQ3rTfabBEG3NfPIqL5Mymm+M/yPh17MovCXJHaPF1UStxWQElNIcGeA4C6ppANkS9gP/ogGkcOisc7vzVS1SpSHrYac6HvOukyeepfAKI0RhnzqHcR061fp/0wb4e543Vb97iH/o1wodNhv3iIbiSKYjBxX0c0FkJjSyfWAMk+63JItiTe3sxQGORSWYDRAjvfsl1LTIuUqRrv+2mtPHcMfcghKq16Xe1VtWUYR5ItCVB/bj3kRooeXeKcRv4Do/mUmNGqWfjjibOXuhKjxkjS71pJcaHQUZ6/fGkSGl9IzCwADXaDxeCizW68UbJ1VhV Z1Si/Bjs L/3vCwH2vdbQXJPOpXR7xrKby9Yiht+MEhy+m+W5GY4fXFzlTqycUg4pzEYi47cGjO17xVrcfJiH896MN0UJmlsa4EHULS7x2S1FEQ73DH86yIVTjec9/XMJKNxOa62Yccx+ip74DDDKbTGgxTs+QdSwiRISq4jZBWWrVCeVNWeo/7Y3PIL4ujpklByGc28kpOJJ8W7qB9Wb7fuB+egbK6JbjFnBqHKx99I1BCIBNqEixnHh6gexqnZOjzry5JaPspgoxq1eue+RVzKO/O3JnFhm6FNfBelXXMsY5aJWzHiQ5A7VopGpzTK6aPvrKGbqcCMzvl2sD7LCxffMMZGqo8VA85v09K7w3gBSz2KWE68C/tIeBQwLl87d8OSa9ceZl5n1jNDrpS1SHWYbT2kGDdk+vtZyhimRzmQ5vOk7Wa4B4vuNJ6Y7FvIKXsId7uMn0Ha03kQ5zu3cPU+Q= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add architecture-independent standard error codes, types, and macros for Gunyah hypercalls. Reviewed-by: Dmitry Baryshkov Reviewed-by: Srinivas Kandagatla Reviewed-by: Alex Elder Signed-off-by: Elliot Berman --- include/linux/gunyah.h | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h new file mode 100644 index 0000000000000..1eab631a49b6d --- /dev/null +++ b/include/linux/gunyah.h @@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _LINUX_GUNYAH_H +#define _LINUX_GUNYAH_H + +#include +#include +#include + +/* Matches resource manager's resource types for VM_GET_HYP_RESOURCES RPC */ +enum gunyah_resource_type { + /* clang-format off */ + GUNYAH_RESOURCE_TYPE_BELL_TX = 0, + GUNYAH_RESOURCE_TYPE_BELL_RX = 1, + GUNYAH_RESOURCE_TYPE_MSGQ_TX = 2, + GUNYAH_RESOURCE_TYPE_MSGQ_RX = 3, + GUNYAH_RESOURCE_TYPE_VCPU = 4, + GUNYAH_RESOURCE_TYPE_MEM_EXTENT = 9, + GUNYAH_RESOURCE_TYPE_ADDR_SPACE = 10, + /* clang-format on */ +}; + +struct gunyah_resource { + enum gunyah_resource_type type; + u64 capid; + unsigned int irq; +}; + +/******************************************************************************/ +/* Common arch-independent definitions for Gunyah hypercalls */ +#define GUNYAH_CAPID_INVAL U64_MAX +#define GUNYAH_VMID_ROOT_VM 0xff + +enum gunyah_error { + /* clang-format off */ + GUNYAH_ERROR_OK = 0, + GUNYAH_ERROR_UNIMPLEMENTED = -1, + GUNYAH_ERROR_RETRY = -2, + + GUNYAH_ERROR_ARG_INVAL = 1, + GUNYAH_ERROR_ARG_SIZE = 2, + GUNYAH_ERROR_ARG_ALIGN = 3, + + GUNYAH_ERROR_NOMEM = 10, + + GUNYAH_ERROR_ADDR_OVFL = 20, + GUNYAH_ERROR_ADDR_UNFL = 21, + GUNYAH_ERROR_ADDR_INVAL = 22, + + GUNYAH_ERROR_DENIED = 30, + GUNYAH_ERROR_BUSY = 31, + GUNYAH_ERROR_IDLE = 32, + + GUNYAH_ERROR_IRQ_BOUND = 40, + GUNYAH_ERROR_IRQ_UNBOUND = 41, + + GUNYAH_ERROR_CSPACE_CAP_NULL = 50, + GUNYAH_ERROR_CSPACE_CAP_REVOKED = 51, + GUNYAH_ERROR_CSPACE_WRONG_OBJ_TYPE = 52, + GUNYAH_ERROR_CSPACE_INSUF_RIGHTS = 53, + GUNYAH_ERROR_CSPACE_FULL = 54, + + GUNYAH_ERROR_MSGQUEUE_EMPTY = 60, + GUNYAH_ERROR_MSGQUEUE_FULL = 61, + /* clang-format on */ +}; + +/** + * gunyah_error_remap() - Remap Gunyah hypervisor errors into a Linux error code + * @gunyah_error: Gunyah hypercall return value + */ +static inline int gunyah_error_remap(enum gunyah_error gunyah_error) +{ + switch (gunyah_error) { + case GUNYAH_ERROR_OK: + return 0; + case GUNYAH_ERROR_NOMEM: + return -ENOMEM; + case GUNYAH_ERROR_DENIED: + case GUNYAH_ERROR_CSPACE_CAP_NULL: + case GUNYAH_ERROR_CSPACE_CAP_REVOKED: + case GUNYAH_ERROR_CSPACE_WRONG_OBJ_TYPE: + case GUNYAH_ERROR_CSPACE_INSUF_RIGHTS: + return -EACCES; + case GUNYAH_ERROR_CSPACE_FULL: + case GUNYAH_ERROR_BUSY: + case GUNYAH_ERROR_IDLE: + return -EBUSY; + case GUNYAH_ERROR_IRQ_BOUND: + case GUNYAH_ERROR_IRQ_UNBOUND: + case GUNYAH_ERROR_MSGQUEUE_FULL: + case GUNYAH_ERROR_MSGQUEUE_EMPTY: + return -EIO; + case GUNYAH_ERROR_UNIMPLEMENTED: + return -EOPNOTSUPP; + case GUNYAH_ERROR_RETRY: + return -EAGAIN; + default: + return -EINVAL; + } +} + +#endif From patchwork Thu Feb 22 23:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B93D2C54798 for ; Thu, 22 Feb 2024 23:16:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 893F56B0081; Thu, 22 Feb 2024 18:16:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 81BB26B0082; Thu, 22 Feb 2024 18:16:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F94E6B0083; Thu, 22 Feb 2024 18:16:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 337856B0081 for ; Thu, 22 Feb 2024 18:16:41 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 102A3C0FB0 for ; Thu, 22 Feb 2024 23:16:41 +0000 (UTC) X-FDA: 81821001402.01.9BF43C6 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf18.hostedemail.com (Postfix) with ESMTP id B84181C000A for ; Thu, 22 Feb 2024 23:16:38 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=LBicNnmR; spf=pass (imf18.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643798; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A36rVBxRzwwYws7z67mghCzAFr1Mob2Eu/RgXgB0b8s=; b=HPAUd3IhxGxz6bJMsiC7D30Ys4Q1yNpjHjgmzmtMub2LmBiK3mCgdptoEF//bXMEk5db0s tlX1CqaYGbGyEm59T8ABTDiJCglUNWpPCnVDZacgLaBd3WPY6nHna319yZttKeDv98OCHB NwHEL4QXT9k921LQKwOKH5xGdP2THtc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643798; a=rsa-sha256; cv=none; b=eTOM/Tdf+fY0BVLHuKrVPyzEB6H7zPINtLqsRvHOJInGJ8nPj8AbLYHRyanmXaJ33cccOh OgLh4hvEcKvndRJN04sxytTVZtyDfuRCDin20P6/0nmbzPmYc9YVC7AtG/yAQI1iGserXD s71xfj06f9jLYJj/HEjRlyHgBDzgWLk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=LBicNnmR; spf=pass (imf18.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLPUKg007186; Thu, 22 Feb 2024 23:16:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=A36rVBxRzwwYws7z67mghCzAFr1Mob2Eu/RgXgB0b8s =; b=LBicNnmR0EkJC4Gz4/9sUf2NrVBG8wYTzpSzzU0mQMzeaJyXteciYFnkxq1 iiNPtmU/IS1cgHW4m/Id6NMA4FYr+EpAHeLTDIM9F2Fa5STp5FPdWvzcqX0dN/1d GHLTcTNz+TmxuSPSxMuifmjWHoGKKD69PnUYXw2tz016iwv9PZckyagqmeMokAqJ entxi/wAd3D76hPFvddIu7cl6uSPLj8Sz2nDRUw8RmQ8KJLx/OmYWRltlZMa9ZGE m7G5GpJljaZmswRWgHBAj/Wi0psxZR23oI+CoPQt8NUAGcrZr77hqjrp8E2zlRPM 5ozZ+GUpC4bk4MvbBvqRptw4+kA== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we1b0jxsm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:30 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGTJj018202 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:29 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:28 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:27 -0800 Subject: [PATCH v17 04/35] virt: gunyah: Add hypercalls to identify Gunyah MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-4-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: eftMgImgDA3yBDTBLyZQNqa-22o84NnL X-Proofpoint-GUID: eftMgImgDA3yBDTBLyZQNqa-22o84NnL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: B84181C000A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: kie4cg56kp4u4t4mhqcc77suot6dmswe X-HE-Tag: 1708643798-198436 X-HE-Meta: U2FsdGVkX18i0CM2+gk5b1zF6b+k8dBSKWbglHntOCIhadnTfsQDPDubCgpVrvcCabnbs6zxBl8vEugzET0+FiziuwobVdRCeCdSwsgv59eyWXZrBaKOeBFAKioriNcoM57ed0KC8S4OlTlN5i0QxVC99qqJxx0oN1tNBlyRkDTHtMByUb3whfg8DUms312tN3VJ6iP97f6DJMTUGdo4CNPwBeqH80h7/zQ3FWXbF/+Eyitk5ywJh6wCFVlVJogojiYUzLo66rsLjCuDldQjl/tLrh7qdGBbZpxLxRB/dlMAt3dQIYfhHJb5mpRhwRJ+nlZCSsBeBHQWgZc6uf50b+9/1IeyRx/r4X9vnMrROzMeccL/n32mdo5tDRmH+jN8jW8tIUrY2GgppscE7EqJRm0Aavv9UH9q8/gHdHeh2Uss3xwC73TB8y4F6e5wFHgNN5k3qZP9M8pulRHAsC2o0qZOIXPqS7wFcgAAJf0UsKm3HI0zU5ikoEevRRYwL/Dtv44vLkYCLZ+MLyPOlMuRJZrMon8FSDfop89VBO9aN6d5uFZEzWQ9zxnhz7lMxPiLhYcu2nwlx2CrZIDmM2YwVW1Ylo0gzV7tncZbNbXsl7SbRkQAEdP+g1yFxG6cZHHHJkk5iN4jlOdSpjn5tzLc0ycSfzxD0cw2J/TiKJJzf71ScExUa256znkGV3IbevP3RbVaeQRWFosz2HSNw9oc/a04D/eMgs/O2iKgbP6Qb+OByShidxToTMlnzFH3IdrERkizqsrJvZ3DmUM11/hP1CeQcO2PRp34gP5HBjbRubUgTkNl/W4M6rLapGbYwnJYHnN6gsl1FKB1pQkk3jEMqrmma7pOHB1SlSv6LvqmVuBYnqNRbHQndKzO51pX/8LqbeRXdL7rKBY7V2CnGTPWkMhKdgRcofP/tnpEVBcSo6kIiOCqrPnetCz1NMYm9sezTo8fXg/xqVYZVCNOwF1 jy11c100 lw98aYZ4xDmfxvivSvA7Rgz8NCd5xwmuVRmUTF3hxsgImwZuD0rOnxYhyU9rxdOncjYYJOasLnZX9fo49yE4u7eGEtMHI2Nr1Jda1Qgj7SV2oXLuFlqvw/DG4XEgrdnIgDSIu9It2waPuxclAMQIH3Fu7HlJJnjlE/7whtphyQ1kuWUS/pfaxzKQugenzTESEm4cR6FiGvEnXVUoQZ4n7Mrz+i+2w9jVBPIrwH6N5Sr4unCBL9P6YetDOoGHSObCSowSMv6CcI5UJikinJvJUH8y1oaHHx03O8ntuX2Y8MfNsyA9CC70WnOLUTBKJrRLiQ3KX54L12KXZ6N7FSIHgkddTnIu0xwti4T5clWYPnPdeg5bISSFIo9GEvU3mQH6g748/ytOLqv6c6icHold8PJVEDTU87RnqDgGncyiObvADN9IUyc/PXUmct6rLk7IV+67JVgSdadursuymi/LY+0O3Xg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add hypercalls to identify when Linux is running in a virtual machine under Gunyah. There are two calls to help identify Gunyah: 1. gh_hypercall_get_uid() returns a UID when running under a Gunyah hypervisor. 2. gh_hypercall_hyp_identify() returns build information and a set of feature flags that are supported by Gunyah. Reviewed-by: Srinivas Kandagatla Reviewed-by: Alex Elder Signed-off-by: Elliot Berman --- arch/arm64/Kbuild | 1 + arch/arm64/gunyah/Makefile | 3 ++ arch/arm64/gunyah/gunyah_hypercall.c | 62 ++++++++++++++++++++++++++++++++++++ drivers/virt/Kconfig | 2 ++ drivers/virt/gunyah/Kconfig | 12 +++++++ include/linux/gunyah.h | 38 ++++++++++++++++++++++ 6 files changed, 118 insertions(+) diff --git a/arch/arm64/Kbuild b/arch/arm64/Kbuild index 5bfbf7d79c99b..e4847ba0e3c95 100644 --- a/arch/arm64/Kbuild +++ b/arch/arm64/Kbuild @@ -3,6 +3,7 @@ obj-y += kernel/ mm/ net/ obj-$(CONFIG_KVM) += kvm/ obj-$(CONFIG_XEN) += xen/ obj-$(subst m,y,$(CONFIG_HYPERV)) += hyperv/ +obj-$(CONFIG_GUNYAH) += gunyah/ obj-$(CONFIG_CRYPTO) += crypto/ # for cleaning diff --git a/arch/arm64/gunyah/Makefile b/arch/arm64/gunyah/Makefile new file mode 100644 index 0000000000000..84f1e38cafb1e --- /dev/null +++ b/arch/arm64/gunyah/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_GUNYAH) += gunyah_hypercall.o diff --git a/arch/arm64/gunyah/gunyah_hypercall.c b/arch/arm64/gunyah/gunyah_hypercall.c new file mode 100644 index 0000000000000..d44663334f381 --- /dev/null +++ b/arch/arm64/gunyah/gunyah_hypercall.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include + +/* {c1d58fcd-a453-5fdb-9265-ce36673d5f14} */ +static const uuid_t GUNYAH_UUID = UUID_INIT(0xc1d58fcd, 0xa453, 0x5fdb, 0x92, + 0x65, 0xce, 0x36, 0x67, 0x3d, 0x5f, + 0x14); + +bool arch_is_gunyah_guest(void) +{ + struct arm_smccc_res res; + uuid_t uuid; + u32 *up; + + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, &res); + + up = (u32 *)&uuid.b[0]; + up[0] = lower_32_bits(res.a0); + up[1] = lower_32_bits(res.a1); + up[2] = lower_32_bits(res.a2); + up[3] = lower_32_bits(res.a3); + + return uuid_equal(&uuid, &GUNYAH_UUID); +} +EXPORT_SYMBOL_GPL(arch_is_gunyah_guest); + +#define GUNYAH_HYPERCALL(fn) \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_VENDOR_HYP, fn) + +/* clang-format off */ +#define GUNYAH_HYPERCALL_HYP_IDENTIFY GUNYAH_HYPERCALL(0x8000) +/* clang-format on */ + +/** + * gunyah_hypercall_hyp_identify() - Returns build information and feature flags + * supported by Gunyah. + * @hyp_identity: filled by the hypercall with the API info and feature flags. + */ +void gunyah_hypercall_hyp_identify( + struct gunyah_hypercall_hyp_identify_resp *hyp_identity) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GUNYAH_HYPERCALL_HYP_IDENTIFY, &res); + + hyp_identity->api_info = res.a0; + hyp_identity->flags[0] = res.a1; + hyp_identity->flags[1] = res.a2; + hyp_identity->flags[2] = res.a3; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_hyp_identify); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls"); diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index 40129b6f0eca4..172a6a12073c3 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -50,4 +50,6 @@ source "drivers/virt/acrn/Kconfig" source "drivers/virt/coco/Kconfig" +source "drivers/virt/gunyah/Kconfig" + endif diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig new file mode 100644 index 0000000000000..6f4c85db80b52 --- /dev/null +++ b/drivers/virt/gunyah/Kconfig @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config GUNYAH + tristate "Gunyah Virtualization drivers" + depends on ARM64 + help + The Gunyah drivers are the helper interfaces that run in a guest VM + such as basic inter-VM IPC and signaling mechanisms, and higher level + services such as memory/device sharing, IRQ sharing, and so on. + + Say Y/M here to enable the drivers needed to interact in a Gunyah + virtual environment. diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 1eab631a49b6d..33bcbd22d39f7 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -6,9 +6,11 @@ #ifndef _LINUX_GUNYAH_H #define _LINUX_GUNYAH_H +#include #include #include #include +#include /* Matches resource manager's resource types for VM_GET_HYP_RESOURCES RPC */ enum gunyah_resource_type { @@ -103,4 +105,40 @@ static inline int gunyah_error_remap(enum gunyah_error gunyah_error) } } +enum gunyah_api_feature { + /* clang-format off */ + GUNYAH_FEATURE_DOORBELL = 1, + GUNYAH_FEATURE_MSGQUEUE = 2, + GUNYAH_FEATURE_VCPU = 5, + GUNYAH_FEATURE_MEMEXTENT = 6, + /* clang-format on */ +}; + +bool arch_is_gunyah_guest(void); + +#define GUNYAH_API_V1 1 + +/* Other bits reserved for future use and will be zero */ +/* clang-format off */ +#define GUNYAH_API_INFO_API_VERSION_MASK GENMASK_ULL(13, 0) +#define GUNYAH_API_INFO_BIG_ENDIAN BIT_ULL(14) +#define GUNYAH_API_INFO_IS_64BIT BIT_ULL(15) +#define GUNYAH_API_INFO_VARIANT_MASK GENMASK_ULL(63, 56) +/* clang-format on */ + +struct gunyah_hypercall_hyp_identify_resp { + u64 api_info; + u64 flags[3]; +}; + +static inline u16 +gunyah_api_version(const struct gunyah_hypercall_hyp_identify_resp *gunyah_api) +{ + return FIELD_GET(GUNYAH_API_INFO_API_VERSION_MASK, + gunyah_api->api_info); +} + +void gunyah_hypercall_hyp_identify( + struct gunyah_hypercall_hyp_identify_resp *hyp_identity); + #endif From patchwork Thu Feb 22 23:16:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 663F7C47DD9 for ; Thu, 22 Feb 2024 23:21:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED8CC6B00C1; Thu, 22 Feb 2024 18:21:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E89016B00C7; Thu, 22 Feb 2024 18:21:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D29536B00C8; Thu, 22 Feb 2024 18:21:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C30B26B00C1 for ; Thu, 22 Feb 2024 18:21:31 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 91907121026 for ; Thu, 22 Feb 2024 23:21:31 +0000 (UTC) X-FDA: 81821013582.22.4022406 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf02.hostedemail.com (Postfix) with ESMTP id 6B0828000D for ; Thu, 22 Feb 2024 23:21:29 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=fOFR2rDW; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf02.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708644089; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zTKiLE99qoQyKhcmKq/otKW5FYYceuLhD8QduGBLZjM=; b=uR6q3TIhRZGW0zCG0W0uMQ0516HCPlQ6tJieHZ7d2yuD14ibdb9swGuO+/mLO77fVaOCzh JftthFmrgERJJJM+J0u1on0cOod61UvZ+sBAzjlOCh4Zf0mPyEuv7TiFqQS0NVJhdnI+Ff JJJ/tOYmBGgN0HCw0VUZxGjXhXn1B80= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=fOFR2rDW; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf02.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708644089; a=rsa-sha256; cv=none; b=GPmvhZ+U7U08ltg/2BhmSCtQCbilHTB8EKdawNgu/fnEL3bxJPngdUWe2jE+/uT0BD273X hEgQkE7fk9XLGrtW24wGDtMknVL1n+K4m+3DeBLRo8hD3AMMR8JmV8CegcnLzAhvrMdLpy V6VwYA/emWuUsmj056iA2OvMS8sjU0A= Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLfk2d024250; Thu, 22 Feb 2024 23:16:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=zTKiLE99qoQyKhcmKq/otKW5FYYceuLhD8QduGBLZjM =; b=fOFR2rDWSSrWriwlEV2Og5S38dW0zz5pIta8m/jYNUHxgIZcZQfHJrp2HBU MDVriFOUqEKz4KLM3CGvlHrpGq9D+lulPJ0X5EePnlLSK80OrEJvZqG30y0cTicP T78lGCM9mWtq00Kq96Ljaf35uAknk/odRRfK7diKtFLE0dhb7iuBbW7D9o8m0CId NgkLWyDAv0F7ESFkGxwIs3dLbzYYFFhM1N8GNbHe8w9we3rjlMkEsXVI+ielc4ZG mgAS+at1hVxio9fbXcC+49yIlbVcQi/vxhU6Z+z/a6GR2wdFdfkwsLiyNOPB8WIE 7SOd1/O0O/iwMp9xSb5o62i2cgQ== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3weedkr5eu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:31 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGUjt025515 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:30 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:29 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:28 -0800 Subject: [PATCH v17 05/35] virt: gunyah: Add hypervisor driver MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-5-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 3-_c8wKoLLhIAOm41mkJiy4fqOWdXiXm X-Proofpoint-GUID: 3-_c8wKoLLhIAOm41mkJiy4fqOWdXiXm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220178 X-Rspamd-Queue-Id: 6B0828000D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 73chzh53u7z6cqz7bb6udtyak516wzi3 X-HE-Tag: 1708644089-258918 X-HE-Meta: U2FsdGVkX1+HnloAXa1tt/OYQL/2Kha0cWiGZDPUZM0tHQE5DhHtJ4NH4bi6RdtR43PfIstHEqMXHykcUTLB9o7VFPG9/a2dj4XZv1PCVZAVoxt80cv/PanvHoyhwCCaeAtriJw0iihXcpbt8Wy06vj51smXBaFn+yuePrFdUhf7G0j7Sy3IX4+WLRBbXm3+3QbO6RIJ0BuLoeeLYa+YW/r8Dsojj2PhYLkmnZ4rThFUNP+WG8VkWJE61lKFpal5/AQPcgjHcQYLfL1mB8xq8onyc62JKY4u1nSdExsMFCm88IARC3w/d86jr0BLyU5Q1xiRwX5RpP9vnnUBjhM2FvkY+cdEPeFRlRbd5FyUSuASMSMxu5C2cdsJJus9dxskSNHWQYp6YV3nXAZgQd+tIDYTNPPH9cEmMvZL87V7HNP7Tle+nR1dMfb8g4r5BseuRvIOZlUhLBOy5QZm1/4tTXDeaBUZ1cMXtuYNMk1AEgN+Tx0ZlVRvggIpXNbuX7fs0orjwLA7CIkgIx8Zh5hGMDEZV5YE+YaVhVmOKJSJpcdSEoXoUqSEHaxeBnIx2xwlTP9/cqenE521nT7BN2/AOaoEuXSXFuytvdaemW0TzojaGH7QH7cC7CA7j6/hKE1tKc+rJIHsgpON6vMQ7N7eemHypadx87MYP4TVQBB5QjitibsU23emaRUMhQgh7TCwdjwHJHo+CNgnVU3Qyl9cUXey4bVHreX9vRe4pTcZDuCn3B5KRSWxQlqooQurpB1RhboVxVg/Y18rBl7eOPAbrG4x0kBVZgoe7mN4YFSmJAFRoX8nDdFSIUmPYUk3AFXjKrkNwwJCez6/Te1JqJWXegrRjqGsGteFLsKZPELJgF7/PO/Mw7tvwOiG1DVEJlAMx1/nOHgqGYrrRWwyE1SnVj5xyevqPtjKegv3JklnhrU4ROzQ7nWZg6h4Hn9/vzl56HUXp1ef09SAcjoQjjR 4aIO6UDQ BznL1an/srRZG4FKPoWxg2MftHka76WksEmh0Ee5zFXv8rH+iNaU5LEGEsOgu3r1sMj5VTPIrrD2zPJdNymd/weU9HiS9GHYnOc49DtzasC1bGmc8fTOlBXBrZuGPglvxB1vYBbTMQic3Pb1MM7VR/Dld77JBTDq42HpOPC/PVjLYK3XyZAiC5eIpBGGuF+RYmfLQOtnX4adnbmjDBLSFUOyHU7AEq/IyfXNmEU83bPL1wVj2DY9E6wYR6vgEJypXSkLSwRa27z01Xmi8d6sETvgyf9572otV2fac7rW3P0u0CyYCg3TTvvj5oggRz/AkGxfsTRbUtAmjrWSbJmDMZiTuE55+MICQ9uX9HS4DSTkyAKHHqJEywO5WLNcW0QL+axwqW806dyqup1jBfH3/vWsgataXF8zF5lJ92BzjEE4T0CZTFVjN25wrRQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add driver to detect when running under Gunyah. It performs basic identification hypercall and populates the platform bus for resource manager to probe. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- drivers/virt/Makefile | 1 + drivers/virt/gunyah/Makefile | 3 +++ drivers/virt/gunyah/gunyah.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile index f29901bd78205..ef6a3835d078c 100644 --- a/drivers/virt/Makefile +++ b/drivers/virt/Makefile @@ -10,3 +10,4 @@ obj-y += vboxguest/ obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) += acrn/ obj-y += coco/ +obj-y += gunyah/ diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile new file mode 100644 index 0000000000000..34f32110faf9a --- /dev/null +++ b/drivers/virt/gunyah/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_GUNYAH) += gunyah.o diff --git a/drivers/virt/gunyah/gunyah.c b/drivers/virt/gunyah/gunyah.c new file mode 100644 index 0000000000000..ef8a85f275905 --- /dev/null +++ b/drivers/virt/gunyah/gunyah.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include + +static int gunyah_probe(struct platform_device *pdev) +{ + struct gunyah_hypercall_hyp_identify_resp gunyah_api; + + if (!arch_is_gunyah_guest()) + return -ENODEV; + + gunyah_hypercall_hyp_identify(&gunyah_api); + + pr_info("Running under Gunyah hypervisor %llx/v%u\n", + FIELD_GET(GUNYAH_API_INFO_VARIANT_MASK, gunyah_api.api_info), + gunyah_api_version(&gunyah_api)); + + /* Might move this out to individual drivers if there's ever an API version bump */ + if (gunyah_api_version(&gunyah_api) != GUNYAH_API_V1) { + pr_info("Unsupported Gunyah version: %u\n", + gunyah_api_version(&gunyah_api)); + return -ENODEV; + } + + return devm_of_platform_populate(&pdev->dev); +} + +static const struct of_device_id gunyah_of_match[] = { + { .compatible = "gunyah-hypervisor" }, + {} +}; +MODULE_DEVICE_TABLE(of, gunyah_of_match); + +/* clang-format off */ +static struct platform_driver gunyah_driver = { + .probe = gunyah_probe, + .driver = { + .name = "gunyah", + .of_match_table = gunyah_of_match, + } +}; +/* clang-format on */ +module_platform_driver(gunyah_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Driver"); From patchwork Thu Feb 22 23:16:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568226 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E80A8C54798 for ; Thu, 22 Feb 2024 23:16:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 475706B0082; Thu, 22 Feb 2024 18:16:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AF476B0083; Thu, 22 Feb 2024 18:16:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 201B36B0087; Thu, 22 Feb 2024 18:16:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 09D7C6B0083 for ; Thu, 22 Feb 2024 18:16:42 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CD3B3A1469 for ; Thu, 22 Feb 2024 23:16:41 +0000 (UTC) X-FDA: 81821001402.25.59DA856 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf20.hostedemail.com (Postfix) with ESMTP id A00671C0012 for ; Thu, 22 Feb 2024 23:16:39 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=P79kJxu3; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf20.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643799; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=83pzBajTRslKt0o1B0FwsmcpCOmVlVgR5SA87/iFxjI=; b=FK9nK9iEvEbL7Rr+8guaV/O/uoOZQO1oeresoapwBygyk9MRTHOJvC5hdLDvXTKPQc4R/a 52liu/Xqj5jMlPPSNEDMY7VT05b3lPNHb6S09CtVnrnmmpWX6ymlbUVdI8O8PZwKm4wwos UYWvlwl7U7twlNmbsYDtO0EKVVo7orI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=P79kJxu3; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf20.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643799; a=rsa-sha256; cv=none; b=565Ij3SevbP4Fy+KnJyPmXL8Wkcyx87q/Ki/X8X/VQG6iICj9t3H0I4YnvPnyHD8CiEfeP nfQPDG7nrDcTwj7CT2ezb7fFD+/lS1Q12Coj5s3CBEmZy5YsFytKk4Sn2Niz1Ie1Zfitj0 01AmUpeSwUt0WJgjFujqeUKA0GC0nkU= Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMFNlW018116; Thu, 22 Feb 2024 23:16:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=83pzBajTRslKt0o1B0FwsmcpCOmVlVgR5SA87/iFxjI =; b=P79kJxu3zXYn+BomJ0td4R5hcDW8siUXNVPRCQOI4JebfMSoULPHooGLMw9 kE4m36hM0QSzCZ2gCa9b/zFEJ9kpytKYFHWrxHs4rcvGOOM7vTr2gZvD9ulyqSaF Z7T8GFLPCFNbc2wJVcFELaPbDirfLfrShIoPAeBaFbEy8KIenTCewyLvLjEQL98p MpBwVkxzkOhWI7xPHO6HwiLrEsDWr6+x3aOuFpbT1Y4mihZUVKGZgxc+LwjeZWtE 4aJabcRkxa24KIyjtGuBrEG/DN0KklIlSp1x8hfLQ6sdKQed5dFxaO8XW5/RCEvE Ph8TRhNu36j5t7xAC5YBr2iQIAQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we97tgf88-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:31 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGUVJ027669 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:30 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:30 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:29 -0800 Subject: [PATCH v17 06/35] virt: gunyah: msgq: Add hypercalls to send and receive messages MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-6-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: VfnP53t9g2l9KuenPJEO6MN8h2KOj3Pm X-Proofpoint-ORIG-GUID: VfnP53t9g2l9KuenPJEO6MN8h2KOj3Pm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 adultscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 mlxlogscore=965 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: A00671C0012 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: pksfnq3wotcnq7fsjiyperih5d7ynzad X-HE-Tag: 1708643799-950196 X-HE-Meta: U2FsdGVkX18hZMiiAGR3kDNBGNBiKyCayz/CrVp2Conl37BQhAfb/g69+fjFWEUnz2b+N2BMBLyzs4UVEarR+pDPZDJNfYE7BrCHzi9WN5h0UzGNDToImGnct6VuaMViMi+zX9MoAov2RT4M9hIT+ckJM5UeRfWBojQVGudVTLH9D3RYOO23MImPYIyzEjAb7pZ/EhEW8rfp4zbzA/8icSyg6J66xUrkDnBs0MtCgOH8LiPZcWd3T6/ptIJ6UfROkyMYwUOToyyRVcW2FmtxRy8RQYZVSgogGJ+360AueufiU9e43qJcdVFJ8B67KD/sxBhoScju5Q8UBeknpVMFwsWzPm3Lceclc7O3d7X7wNEpifjSp/d+eoxeWCoQ7giw0yl0sJOLx8WFhTtLZknQqBjOD1IAUZy1fOmd6yXA+1stinE3I/VOAbCMx7r1gE5oxgXx+WDQTD5J2lySpnl2r7Am9rsR9QJ1vbZfTByx37pxISFMNn3DGxihC48umRM6PhanrT8Oq0QDBGcRfs61fYEcKBc02eJ/4XdbM4GKYCcY+IRXEXEMHSj7x4q9t5+eQGdDAq7Kv2xizFBdlbtTfTZEbNlhvrY/909WfsiY9LF09rFjIxnMSF5YD7nWtXb0YOZj+W/lj4VQLxTOUDwh7s/6RrIX5z2p4qLnd9WeMln/0P8j54RI+FA2aIgQfVeuc5xCrvLVvwLIg5QztMl+ucJz6rRrfp4EKPlwgBftkSXpGTizmUdpAbkDPm2No7ODHnjxZIypQuoiqA3GZqJSCbty7iwi6xcbro+Thc3GuSRUD/rNbAac7hsWqK44DFTqT6BLxMCTYpeQuz3p1egG2z9xVDGe0cQQH7mDLfCGQe1xNn9IPy7vgFdR5gIqeWKtiMrNRI4UBBAxiC7lWZaPzCkdq+h+7EqSJZ27oPnKI7ocJ0Drwe4srK7QRRXBt197dObqIiYfxBsTEOQdF/9 XubAXeGt Hu1UDjNZbCB5tbDSN8LgsL8MWgD6hUBj8IMbe+idL15GqKh2vnQQf7oxSFRRhR6J2KMy0Ov8saG71643s50r5zJ2v0gh7dLsC2wr+Nf+WDK59oR+107qF7im0O2abWQNCDHPsJA7zTzuUEO3gzlKpESTmzsa3gybA3kYMwIKPUkHkh8bTNEkFDJXidC0PFiFX0xIOEljcb7mRkmMHQjseqJ+5/tMVFs8iL80buxLHWz1Lq2IXW7YCZ0nuQHZuvTyrKEm8jjXAIcAaykXWOKypJlhP23m6KQE8pa5eu85QDOhGb2SFLhjHQRe/5vvqu/NGK3NtTMiFqjyo5h+aV6PKUu9B94U8rf1BfyJ1IbuPmRow1rPjB1CJWu5ujliu+nIXbqBxvV1ggrjXLtSO9kVR06DN8cQdh2mAxXbsBeqyC8kVD/BbIs8L+7wSHA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add hypercalls to send and receive messages on a Gunyah message queue. Reviewed-by: Alex Elder Reviewed-by: Srinivas Kandagatla Signed-off-by: Elliot Berman --- arch/arm64/gunyah/gunyah_hypercall.c | 55 ++++++++++++++++++++++++++++++++++++ include/linux/gunyah.h | 8 ++++++ 2 files changed, 63 insertions(+) diff --git a/arch/arm64/gunyah/gunyah_hypercall.c b/arch/arm64/gunyah/gunyah_hypercall.c index d44663334f381..1302e128be6e9 100644 --- a/arch/arm64/gunyah/gunyah_hypercall.c +++ b/arch/arm64/gunyah/gunyah_hypercall.c @@ -37,6 +37,8 @@ EXPORT_SYMBOL_GPL(arch_is_gunyah_guest); /* clang-format off */ #define GUNYAH_HYPERCALL_HYP_IDENTIFY GUNYAH_HYPERCALL(0x8000) +#define GUNYAH_HYPERCALL_MSGQ_SEND GUNYAH_HYPERCALL(0x801B) +#define GUNYAH_HYPERCALL_MSGQ_RECV GUNYAH_HYPERCALL(0x801C) /* clang-format on */ /** @@ -58,5 +60,58 @@ void gunyah_hypercall_hyp_identify( } EXPORT_SYMBOL_GPL(gunyah_hypercall_hyp_identify); +/** + * gunyah_hypercall_msgq_send() - Send a buffer on a message queue + * @capid: capability ID of the message queue to add message + * @size: Size of @buff + * @buff: Address of buffer to send + * @tx_flags: See GUNYAH_HYPERCALL_MSGQ_TX_FLAGS_* + * @ready: If the send was successful, ready is filled with true if more + * messages can be sent on the queue. If false, then the tx IRQ will + * be raised in future when send can succeed. + */ +enum gunyah_error gunyah_hypercall_msgq_send(u64 capid, size_t size, void *buff, + u64 tx_flags, bool *ready) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GUNYAH_HYPERCALL_MSGQ_SEND, capid, size, + (uintptr_t)buff, tx_flags, 0, &res); + + if (res.a0 == GUNYAH_ERROR_OK) + *ready = !!res.a1; + + return res.a0; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_msgq_send); + +/** + * gunyah_hypercall_msgq_recv() - Send a buffer on a message queue + * @capid: capability ID of the message queue to add message + * @buff: Address of buffer to copy received data into + * @size: Size of @buff + * @recv_size: If the receive was successful, recv_size is filled with the + * size of data received. Will be <= size. + * @ready: If the receive was successful, ready is filled with true if more + * messages are ready to be received on the queue. If false, then the + * rx IRQ will be raised in future when recv can succeed. + */ +enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size, + size_t *recv_size, bool *ready) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GUNYAH_HYPERCALL_MSGQ_RECV, capid, (uintptr_t)buff, + size, 0, &res); + + if (res.a0 == GUNYAH_ERROR_OK) { + *recv_size = res.a1; + *ready = !!res.a2; + } + + return res.a0; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_msgq_recv); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls"); diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 33bcbd22d39f7..acd70f9824253 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -141,4 +141,12 @@ gunyah_api_version(const struct gunyah_hypercall_hyp_identify_resp *gunyah_api) void gunyah_hypercall_hyp_identify( struct gunyah_hypercall_hyp_identify_resp *hyp_identity); +/* Immediately raise RX vIRQ on receiver VM */ +#define GUNYAH_HYPERCALL_MSGQ_TX_FLAGS_PUSH BIT(0) + +enum gunyah_error gunyah_hypercall_msgq_send(u64 capid, size_t size, void *buff, + u64 tx_flags, bool *ready); +enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size, + size_t *recv_size, bool *ready); + #endif From patchwork Thu Feb 22 23:16:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6865DC54798 for ; Thu, 22 Feb 2024 23:16:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2CBA6B0088; Thu, 22 Feb 2024 18:16:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB53D6B0089; Thu, 22 Feb 2024 18:16:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77F0D6B008A; Thu, 22 Feb 2024 18:16:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 575816B0089 for ; Thu, 22 Feb 2024 18:16:43 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 16F071A0F75 for ; Thu, 22 Feb 2024 23:16:43 +0000 (UTC) X-FDA: 81821001486.14.1E0B018 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf10.hostedemail.com (Postfix) with ESMTP id 59EAAC001C for ; Thu, 22 Feb 2024 23:16:40 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=gwzUlP+m; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf10.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643800; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xs6QX/PVs99+AO3++J22K9QrGkiE6UGNqmUbKQxROFk=; b=M/xuvxVT+Psplj9lsSR5J7vmVs0owDxth2AJYS9vOlNFhpIHD4V7H+WKKzSI6B28/laJ4n Cn2NiyIIpuMoBmaZ4DaNb+apiAkyoC9ehzJUIN4jAz0SlTsBrFqrtYS8h9Tm6x2dpaseJo apWnMu8I+O4M+w1Xi3b/vK4X5kLUjeA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=gwzUlP+m; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf10.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643800; a=rsa-sha256; cv=none; b=UbeD72s9VHRlegMfcX6es8QFs9v4h0v4A5Z8EDvZZP783TgEaclnNF+1o0X1qDFavyu/8t EflpLkwzsARhVZkpjcxdp161kdAIKi7Pq1FuvDHwsufp+KFSukjOiDEsWuo9KfR5saiHb6 0cQAnw0ohk+f+ukAQkbapZHOUkQx3GA= Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMembW019040; Thu, 22 Feb 2024 23:16:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=xs6QX/PVs99+AO3++J22K9QrGkiE6UGNqmUbKQxROFk =; b=gwzUlP+m5bc+DROjlrh8po7aReHHAayo+Pdnm+kKBwvVmDAQAAdGLI8yIPJ hpG+MQB0Z+vgPTQ6sRM/A97Blxai7WdGhXSmYnUnJXG/5lk/dU3yLDohaRrtqmGI 1yBG17GOQPnGfWhTXnvzH6WKfCJ+AUpil2YfVVuO5npwUUg9H82yEFNHinltRzF2 c3HkmAbZtZx34UFQ320BbE1YdpZiIgq9OTEHmq8hZQMb995oPrgh/1NO/E3u+WSp heLZ63cDtdG4S7odXQ37Suk0p9+BLlalmBhWkdSp+rB0YvkzKTCL56wmund1Kemi Undglur+bbnQ/9JTsn1JbKXfjrw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we24ajum8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:32 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGVtM015955 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:31 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:30 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:30 -0800 Subject: [PATCH v17 07/35] gunyah: rsc_mgr: Add resource manager RPC core MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-7-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 5QUp0_3NuEc4d57seW4Rl0L0qo0iOE7a X-Proofpoint-ORIG-GUID: 5QUp0_3NuEc4d57seW4Rl0L0qo0iOE7a X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 adultscore=0 mlxlogscore=999 phishscore=0 spamscore=0 mlxscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Stat-Signature: fzkcc8ts6ym4egf1zgjs8xuxh99s377y X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 59EAAC001C X-HE-Tag: 1708643800-162895 X-HE-Meta: U2FsdGVkX1+9AngStfgJWyr3IQDtpshcSmnwXdL/zQpveJueuNiv1Y3gVj1DixHsQ7pTiLofACn0qKBI7j5F2rgQmxLwlPFHK3XxZQNLn+tv4lGLyCTkfrZghw3+yELzSgIpSU8Wv9xgSK1J7OK66zh3umR3PcJXU5GWktgVjRvF2cYGO5DoZyKsBpGOeyYdsYcMXqfuD5rL9l1b0Hk4j78f4BuwoRc6MfThjVl1moFsT8j+eKK4ZCS5OhfwrZP6wSY/gpFi+iB5fb0CMVQmzl0aksbe7PlxbP7RkQLwib135KqU9fCw985oydVQuos8jfjHBVQwVaqCtreP4ALdeo6ELXfo30E3jPeIQf5foJeU4IpNryePSx+5uxn70gY9dhXXtSFl4GXSeNeEVVgFq7P8QpAQZxsnpUvaBkZJG8uAHWN9a2fSIFsi0n6gbdu+Mn22vDJk8mJnwJIyNVCzmNXZ2FdRiQma4utrljKoVAl1kG3NHOyHFPwewn2uH9XeMwPEiHrY7IPByGmX9bXOs3rOXytXveCd1xG7GkoJclY7NU2mWBPibIxmePkoWkgD2jr0u3p3mtso2Hd+WqB/YttHDrWyNAMxYLJpd135Uve6XgK/swM0Pl7uSWKwkp7SDNRB88uc6fApbekf4uHBoO7G47ygmuCXM9w9dxBgEy7WyQSf3Qiq2K0WRmx5Xrr9ubZma4FbWhAG+K2H0hcN1xxpMQAAZ+x1KehCghb7/Q2SufU+H4q5hj0quwNi8sHJRSoCqjOC+DNtx7wm1BBy0++VGjmgTV+xNV2mvXDQsyvh53eYUamwMsf1AJnThMcPaW0VIBqUyY8PsWAhCyl+ZqYEOTgfgv/3S/qB4eKHRQXt8f9Mv/x0WYwWhproz8wNtuIt/6r+bmkNQhrDLTDXmIAHyz+VDJca0ulwKWpDMk7CAtl+52RG3wkP9+o/Bd7ZZttMP8+wGHhm3cnsLIM Jlh3zoV4 aK6mr8BQhF9qpDKXohXBa+Hqy1S5PUIGBaPcN X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The resource manager is a special virtual machine which is always running on a Gunyah system. It provides APIs for creating and destroying VMs, secure memory management, sharing/lending of memory between VMs, and setup of inter-VM communication. Calls to the resource manager are made via message queues. This patch implements the basic probing and RPC mechanism to make those API calls. Request/response calls can be made with gh_rm_call. Drivers can also register to notifications pushed by RM via gh_rm_register_notifier Specific API calls that resource manager supports will be implemented in subsequent patches. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- drivers/virt/gunyah/Makefile | 4 +- drivers/virt/gunyah/rsc_mgr.c | 721 ++++++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/rsc_mgr.h | 26 ++ 3 files changed, 750 insertions(+), 1 deletion(-) diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index 34f32110faf9a..c2308389f5517 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_GUNYAH) += gunyah.o +gunyah_rsc_mgr-y += rsc_mgr.o + +obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o diff --git a/drivers/virt/gunyah/rsc_mgr.c b/drivers/virt/gunyah/rsc_mgr.c new file mode 100644 index 0000000000000..4ac946da0ca7f --- /dev/null +++ b/drivers/virt/gunyah/rsc_mgr.c @@ -0,0 +1,721 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "rsc_mgr.h" + +/* clang-format off */ +#define RM_RPC_API_VERSION_MASK GENMASK(3, 0) +#define RM_RPC_HEADER_WORDS_MASK GENMASK(7, 4) +#define RM_RPC_API_VERSION FIELD_PREP(RM_RPC_API_VERSION_MASK, 1) +#define RM_RPC_HEADER_WORDS FIELD_PREP(RM_RPC_HEADER_WORDS_MASK, \ + (sizeof(struct gunyah_rm_rpc_hdr) / sizeof(u32))) +#define RM_RPC_API (RM_RPC_API_VERSION | RM_RPC_HEADER_WORDS) + +#define RM_RPC_TYPE_CONTINUATION 0x0 +#define RM_RPC_TYPE_REQUEST 0x1 +#define RM_RPC_TYPE_REPLY 0x2 +#define RM_RPC_TYPE_NOTIF 0x3 +#define RM_RPC_TYPE_MASK GENMASK(1, 0) + +#define GUNYAH_RM_MAX_NUM_FRAGMENTS 62 +#define RM_RPC_FRAGMENTS_MASK GENMASK(7, 2) +/* clang-format on */ + +struct gunyah_rm_rpc_hdr { + u8 api; + u8 type; + __le16 seq; + __le32 msg_id; +} __packed; + +struct gunyah_rm_rpc_reply_hdr { + struct gunyah_rm_rpc_hdr hdr; + __le32 err_code; /* GUNYAH_RM_ERROR_* */ +} __packed; + +#define GUNYAH_RM_MSGQ_MSG_SIZE 240 +#define GUNYAH_RM_PAYLOAD_SIZE \ + (GUNYAH_RM_MSGQ_MSG_SIZE - sizeof(struct gunyah_rm_rpc_hdr)) + +/* RM Error codes */ +enum gunyah_rm_error { + /* clang-format off */ + GUNYAH_RM_ERROR_OK = 0x0, + GUNYAH_RM_ERROR_UNIMPLEMENTED = 0xFFFFFFFF, + GUNYAH_RM_ERROR_NOMEM = 0x1, + GUNYAH_RM_ERROR_NORESOURCE = 0x2, + GUNYAH_RM_ERROR_DENIED = 0x3, + GUNYAH_RM_ERROR_INVALID = 0x4, + GUNYAH_RM_ERROR_BUSY = 0x5, + GUNYAH_RM_ERROR_ARGUMENT_INVALID = 0x6, + GUNYAH_RM_ERROR_HANDLE_INVALID = 0x7, + GUNYAH_RM_ERROR_VALIDATE_FAILED = 0x8, + GUNYAH_RM_ERROR_MAP_FAILED = 0x9, + GUNYAH_RM_ERROR_MEM_INVALID = 0xA, + GUNYAH_RM_ERROR_MEM_INUSE = 0xB, + GUNYAH_RM_ERROR_MEM_RELEASED = 0xC, + GUNYAH_RM_ERROR_VMID_INVALID = 0xD, + GUNYAH_RM_ERROR_LOOKUP_FAILED = 0xE, + GUNYAH_RM_ERROR_IRQ_INVALID = 0xF, + GUNYAH_RM_ERROR_IRQ_INUSE = 0x10, + GUNYAH_RM_ERROR_IRQ_RELEASED = 0x11, + /* clang-format on */ +}; + +/** + * struct gunyah_rm_message - Represents a complete message from resource manager + * @payload: Combined payload of all the fragments (msg headers stripped off). + * @size: Size of the payload received so far. + * @msg_id: Message ID from the header. + * @type: RM_RPC_TYPE_REPLY or RM_RPC_TYPE_NOTIF. + * @num_fragments: total number of fragments expected to be received. + * @fragments_received: fragments received so far. + * @reply: Fields used for request/reply sequences + */ +struct gunyah_rm_message { + void *payload; + size_t size; + u32 msg_id; + u8 type; + + u8 num_fragments; + u8 fragments_received; + + /** + * @ret: Linux return code, there was an error processing message + * @seq: Sequence ID for the main message. + * @rm_error: For request/reply sequences with standard replies + * @seq_done: Signals caller that the RM reply has been received + */ + struct { + int ret; + u16 seq; + enum gunyah_rm_error rm_error; + struct completion seq_done; + } reply; +}; + +/** + * struct gunyah_rm - private data for communicating w/Gunyah resource manager + * @dev: pointer to RM platform device + * @tx_ghrsc: message queue resource to TX to RM + * @rx_ghrsc: message queue resource to RX from RM + * @active_rx_message: ongoing gunyah_rm_message for which we're receiving fragments + * @call_xarray: xarray to allocate & lookup sequence IDs for Request/Response flows + * @next_seq: next ID to allocate (for xa_alloc_cyclic) + * @recv_msg: cached allocation for Rx messages + * @send_msg: cached allocation for Tx messages. Must hold @send_lock to manipulate. + * @send_lock: synchronization to allow only one request to be sent at a time + * @send_ready: completed when we know Tx message queue can take more messages + * @nh: notifier chain for clients interested in RM notification messages + */ +struct gunyah_rm { + struct device *dev; + struct gunyah_resource tx_ghrsc; + struct gunyah_resource rx_ghrsc; + struct gunyah_rm_message *active_rx_message; + + struct xarray call_xarray; + u32 next_seq; + + unsigned char recv_msg[GUNYAH_RM_MSGQ_MSG_SIZE]; + unsigned char send_msg[GUNYAH_RM_MSGQ_MSG_SIZE]; + struct mutex send_lock; + struct completion send_ready; + struct blocking_notifier_head nh; +}; + +/** + * gunyah_rm_error_remap() - Remap Gunyah resource manager errors into a Linux error code + * @rm_error: "Standard" return value from Gunyah resource manager + */ +static inline int gunyah_rm_error_remap(enum gunyah_rm_error rm_error) +{ + switch (rm_error) { + case GUNYAH_RM_ERROR_OK: + return 0; + case GUNYAH_RM_ERROR_UNIMPLEMENTED: + return -EOPNOTSUPP; + case GUNYAH_RM_ERROR_NOMEM: + return -ENOMEM; + case GUNYAH_RM_ERROR_NORESOURCE: + return -ENODEV; + case GUNYAH_RM_ERROR_DENIED: + return -EPERM; + case GUNYAH_RM_ERROR_BUSY: + return -EBUSY; + case GUNYAH_RM_ERROR_INVALID: + case GUNYAH_RM_ERROR_ARGUMENT_INVALID: + case GUNYAH_RM_ERROR_HANDLE_INVALID: + case GUNYAH_RM_ERROR_VALIDATE_FAILED: + case GUNYAH_RM_ERROR_MAP_FAILED: + case GUNYAH_RM_ERROR_MEM_INVALID: + case GUNYAH_RM_ERROR_MEM_INUSE: + case GUNYAH_RM_ERROR_MEM_RELEASED: + case GUNYAH_RM_ERROR_VMID_INVALID: + case GUNYAH_RM_ERROR_LOOKUP_FAILED: + case GUNYAH_RM_ERROR_IRQ_INVALID: + case GUNYAH_RM_ERROR_IRQ_INUSE: + case GUNYAH_RM_ERROR_IRQ_RELEASED: + return -EINVAL; + default: + return -EBADMSG; + } +} + +static int gunyah_rm_init_message_payload(struct gunyah_rm_message *message, + const void *msg, size_t hdr_size, + size_t msg_size) +{ + const struct gunyah_rm_rpc_hdr *hdr = msg; + size_t max_buf_size, payload_size; + + if (msg_size < hdr_size) + return -EINVAL; + + payload_size = msg_size - hdr_size; + + message->num_fragments = FIELD_GET(RM_RPC_FRAGMENTS_MASK, hdr->type); + message->fragments_received = 0; + + /* There's not going to be any payload, no need to allocate buffer. */ + if (!payload_size && !message->num_fragments) + return 0; + + if (message->num_fragments > GUNYAH_RM_MAX_NUM_FRAGMENTS) + return -EINVAL; + + max_buf_size = payload_size + + (message->num_fragments * GUNYAH_RM_PAYLOAD_SIZE); + + message->payload = kzalloc(max_buf_size, GFP_KERNEL); + if (!message->payload) + return -ENOMEM; + + memcpy(message->payload, msg + hdr_size, payload_size); + message->size = payload_size; + return 0; +} + +static void gunyah_rm_abort_message(struct gunyah_rm *rm) +{ + kfree(rm->active_rx_message->payload); + + switch (rm->active_rx_message->type) { + case RM_RPC_TYPE_REPLY: + rm->active_rx_message->reply.ret = -EIO; + complete(&rm->active_rx_message->reply.seq_done); + break; + case RM_RPC_TYPE_NOTIF: + fallthrough; + default: + kfree(rm->active_rx_message); + } + + rm->active_rx_message = NULL; +} + +static inline void gunyah_rm_try_complete_message(struct gunyah_rm *rm) +{ + struct gunyah_rm_message *message = rm->active_rx_message; + + if (!message || message->fragments_received != message->num_fragments) + return; + + switch (message->type) { + case RM_RPC_TYPE_REPLY: + complete(&message->reply.seq_done); + break; + case RM_RPC_TYPE_NOTIF: + blocking_notifier_call_chain(&rm->nh, message->msg_id, + message->payload); + + kfree(message->payload); + kfree(message); + break; + default: + dev_err_ratelimited(rm->dev, + "Invalid message type (%u) received\n", + message->type); + gunyah_rm_abort_message(rm); + break; + } + + rm->active_rx_message = NULL; +} + +static void gunyah_rm_process_notif(struct gunyah_rm *rm, const void *msg, + size_t msg_size) +{ + const struct gunyah_rm_rpc_hdr *hdr = msg; + struct gunyah_rm_message *message; + int ret; + + if (rm->active_rx_message) { + dev_err(rm->dev, + "Unexpected new notification, still processing an active message"); + gunyah_rm_abort_message(rm); + } + + message = kzalloc(sizeof(*message), GFP_KERNEL); + if (!message) + return; + + message->type = RM_RPC_TYPE_NOTIF; + message->msg_id = le32_to_cpu(hdr->msg_id); + + ret = gunyah_rm_init_message_payload(message, msg, sizeof(*hdr), + msg_size); + if (ret) { + dev_err(rm->dev, + "Failed to initialize message for notification: %d\n", + ret); + kfree(message); + return; + } + + rm->active_rx_message = message; + + gunyah_rm_try_complete_message(rm); +} + +static void gunyah_rm_process_reply(struct gunyah_rm *rm, const void *msg, + size_t msg_size) +{ + const struct gunyah_rm_rpc_reply_hdr *reply_hdr = msg; + struct gunyah_rm_message *message; + u16 seq_id; + + seq_id = le16_to_cpu(reply_hdr->hdr.seq); + message = xa_load(&rm->call_xarray, seq_id); + + if (!message || message->msg_id != le32_to_cpu(reply_hdr->hdr.msg_id)) + return; + + if (rm->active_rx_message) { + dev_err(rm->dev, + "Unexpected new reply, still processing an active message"); + gunyah_rm_abort_message(rm); + } + + if (gunyah_rm_init_message_payload(message, msg, sizeof(*reply_hdr), + msg_size)) { + dev_err(rm->dev, + "Failed to alloc message buffer for sequence %d\n", + seq_id); + /* Send message complete and error the client. */ + message->reply.ret = -ENOMEM; + complete(&message->reply.seq_done); + return; + } + + message->reply.rm_error = le32_to_cpu(reply_hdr->err_code); + rm->active_rx_message = message; + + gunyah_rm_try_complete_message(rm); +} + +static void gunyah_rm_process_cont(struct gunyah_rm *rm, + struct gunyah_rm_message *message, + const void *msg, size_t msg_size) +{ + const struct gunyah_rm_rpc_hdr *hdr = msg; + size_t payload_size = msg_size - sizeof(*hdr); + + if (!rm->active_rx_message) + return; + + /* + * hdr->fragments and hdr->msg_id preserves the value from first reply + * or notif message. To detect mishandling, check it's still intact. + */ + if (message->msg_id != le32_to_cpu(hdr->msg_id) || + message->num_fragments != + FIELD_GET(RM_RPC_FRAGMENTS_MASK, hdr->type)) { + gunyah_rm_abort_message(rm); + return; + } + + memcpy(message->payload + message->size, msg + sizeof(*hdr), + payload_size); + message->size += payload_size; + message->fragments_received++; + + gunyah_rm_try_complete_message(rm); +} + +static irqreturn_t gunyah_rm_rx(int irq, void *data) +{ + enum gunyah_error gunyah_error; + struct gunyah_rm_rpc_hdr *hdr; + struct gunyah_rm *rm = data; + void *msg = &rm->recv_msg[0]; + size_t len; + bool ready; + + do { + gunyah_error = gunyah_hypercall_msgq_recv(rm->rx_ghrsc.capid, + msg, + sizeof(rm->recv_msg), + &len, &ready); + if (gunyah_error != GUNYAH_ERROR_OK) { + if (gunyah_error != GUNYAH_ERROR_MSGQUEUE_EMPTY) + dev_warn(rm->dev, + "Failed to receive data: %d\n", + gunyah_error); + return IRQ_HANDLED; + } + + if (len < sizeof(*hdr)) { + dev_err_ratelimited( + rm->dev, + "Too small message received. size=%ld\n", len); + continue; + } + + hdr = msg; + if (hdr->api != RM_RPC_API) { + dev_err(rm->dev, "Unknown RM RPC API version: %x\n", + hdr->api); + return IRQ_HANDLED; + } + + switch (FIELD_GET(RM_RPC_TYPE_MASK, hdr->type)) { + case RM_RPC_TYPE_NOTIF: + gunyah_rm_process_notif(rm, msg, len); + break; + case RM_RPC_TYPE_REPLY: + gunyah_rm_process_reply(rm, msg, len); + break; + case RM_RPC_TYPE_CONTINUATION: + gunyah_rm_process_cont(rm, rm->active_rx_message, msg, + len); + break; + default: + dev_err(rm->dev, + "Invalid message type (%lu) received\n", + FIELD_GET(RM_RPC_TYPE_MASK, hdr->type)); + return IRQ_HANDLED; + } + } while (ready); + + return IRQ_HANDLED; +} + +static irqreturn_t gunyah_rm_tx(int irq, void *data) +{ + struct gunyah_rm *rm = data; + + complete(&rm->send_ready); + + return IRQ_HANDLED; +} + +static int gunyah_rm_msgq_send(struct gunyah_rm *rm, size_t size, bool push) +{ + const u64 tx_flags = push ? GUNYAH_HYPERCALL_MSGQ_TX_FLAGS_PUSH : 0; + enum gunyah_error gunyah_error; + void *data = &rm->send_msg[0]; + bool ready; + + lockdep_assert_held(&rm->send_lock); + +again: + wait_for_completion(&rm->send_ready); + gunyah_error = gunyah_hypercall_msgq_send(rm->tx_ghrsc.capid, size, + data, tx_flags, &ready); + + /* Should never happen because Linux properly tracks the ready-state of the msgq */ + if (WARN_ON(gunyah_error == GUNYAH_ERROR_MSGQUEUE_FULL)) + goto again; + + if (ready) + complete(&rm->send_ready); + + return gunyah_error_remap(gunyah_error); +} + +static int gunyah_rm_send_request(struct gunyah_rm *rm, u32 message_id, + const void *req_buf, size_t req_buf_size, + struct gunyah_rm_message *message) +{ + size_t buf_size_remaining = req_buf_size; + const void *req_buf_curr = req_buf; + struct gunyah_rm_rpc_hdr *hdr = + (struct gunyah_rm_rpc_hdr *)&rm->send_msg[0]; + struct gunyah_rm_rpc_hdr hdr_template; + void *payload = hdr + 1; + u32 cont_fragments = 0; + size_t payload_size; + bool push; + int ret; + + if (req_buf_size > + GUNYAH_RM_MAX_NUM_FRAGMENTS * GUNYAH_RM_PAYLOAD_SIZE) { + dev_warn( + rm->dev, + "Limit (%lu bytes) exceeded for the maximum message size: %lu\n", + GUNYAH_RM_MAX_NUM_FRAGMENTS * GUNYAH_RM_PAYLOAD_SIZE, + req_buf_size); + dump_stack(); + return -E2BIG; + } + + if (req_buf_size) + cont_fragments = (req_buf_size - 1) / GUNYAH_RM_PAYLOAD_SIZE; + + hdr_template.api = RM_RPC_API; + hdr_template.type = FIELD_PREP(RM_RPC_TYPE_MASK, RM_RPC_TYPE_REQUEST) | + FIELD_PREP(RM_RPC_FRAGMENTS_MASK, cont_fragments); + hdr_template.seq = cpu_to_le16(message->reply.seq); + hdr_template.msg_id = cpu_to_le32(message_id); + + ret = mutex_lock_interruptible(&rm->send_lock); + if (ret) + return ret; + + do { + *hdr = hdr_template; + + /* Copy payload */ + payload_size = min(buf_size_remaining, GUNYAH_RM_PAYLOAD_SIZE); + memcpy(payload, req_buf_curr, payload_size); + req_buf_curr += payload_size; + buf_size_remaining -= payload_size; + + /* Only the last message should have push flag set */ + push = !buf_size_remaining; + ret = gunyah_rm_msgq_send(rm, sizeof(*hdr) + payload_size, + push); + if (ret) + break; + + hdr_template.type = + FIELD_PREP(RM_RPC_TYPE_MASK, RM_RPC_TYPE_CONTINUATION) | + FIELD_PREP(RM_RPC_FRAGMENTS_MASK, cont_fragments); + } while (buf_size_remaining); + + mutex_unlock(&rm->send_lock); + return ret; +} + +/** + * gunyah_rm_call: Achieve request-response type communication with RPC + * @rm: Pointer to Gunyah resource manager internal data + * @message_id: The RM RPC message-id + * @req_buf: Request buffer that contains the payload + * @req_buf_size: Total size of the payload + * @resp_buf: Pointer to a response buffer + * @resp_buf_size: Size of the response buffer + * + * Make a request to the Resource Manager and wait for reply back. For a successful + * response, the function returns the payload. The size of the payload is set in + * resp_buf_size. The resp_buf must be freed by the caller when 0 is returned + * and resp_buf_size != 0. + * + * req_buf should be not NULL for req_buf_size >0. If req_buf_size == 0, + * req_buf *can* be NULL and no additional payload is sent. + * + * Context: Process context. Will sleep waiting for reply. + * Return: 0 on success. <0 if error. + */ +int gunyah_rm_call(struct gunyah_rm *rm, u32 message_id, const void *req_buf, + size_t req_buf_size, void **resp_buf, size_t *resp_buf_size) +{ + struct gunyah_rm_message message = { 0 }; + u32 seq_id; + int ret; + + /* message_id 0 is reserved. req_buf_size implies req_buf is not NULL */ + if (!rm || !message_id || (!req_buf && req_buf_size)) + return -EINVAL; + + message.type = RM_RPC_TYPE_REPLY; + message.msg_id = message_id; + + message.reply.seq_done = + COMPLETION_INITIALIZER_ONSTACK(message.reply.seq_done); + + /* Allocate a new seq number for this message */ + ret = xa_alloc_cyclic(&rm->call_xarray, &seq_id, &message, xa_limit_16b, + &rm->next_seq, GFP_KERNEL); + if (ret < 0) + return ret; + message.reply.seq = lower_16_bits(seq_id); + + /* Send the request to the Resource Manager */ + ret = gunyah_rm_send_request(rm, message_id, req_buf, req_buf_size, + &message); + if (ret < 0) { + dev_warn(rm->dev, "Failed to send request. Error: %d\n", ret); + goto out; + } + + /* + * Wait for response. Uninterruptible because rollback based on what RM did to VM + * requires us to know how RM handled the call. + */ + wait_for_completion(&message.reply.seq_done); + + /* Check for internal (kernel) error waiting for the response */ + if (message.reply.ret) { + ret = message.reply.ret; + goto out; + } + + /* Got a response, did resource manager give us an error? */ + if (message.reply.rm_error != GUNYAH_RM_ERROR_OK) { + dev_warn(rm->dev, "RM rejected message %08x. Error: %d\n", + message_id, message.reply.rm_error); + ret = gunyah_rm_error_remap(message.reply.rm_error); + kfree(message.payload); + goto out; + } + + /* Everything looks good, return the payload */ + if (resp_buf_size) + *resp_buf_size = message.size; + + if (message.size && resp_buf) { + *resp_buf = message.payload; + } else { + /* kfree in case RM sent us multiple fragments but never any data in + * those fragments. We would've allocated memory for it, but message.size == 0 + */ + kfree(message.payload); + } + +out: + xa_erase(&rm->call_xarray, message.reply.seq); + return ret; +} + +int gunyah_rm_notifier_register(struct gunyah_rm *rm, struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&rm->nh, nb); +} +EXPORT_SYMBOL_GPL(gunyah_rm_notifier_register); + +int gunyah_rm_notifier_unregister(struct gunyah_rm *rm, + struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&rm->nh, nb); +} +EXPORT_SYMBOL_GPL(gunyah_rm_notifier_unregister); + +static int gunyah_platform_probe_capability(struct platform_device *pdev, + int idx, + struct gunyah_resource *ghrsc) +{ + int ret; + + ghrsc->irq = platform_get_irq(pdev, idx); + if (ghrsc->irq < 0) { + dev_err(&pdev->dev, "Failed to get %s irq: %d\n", + idx ? "rx" : "tx", ghrsc->irq); + return ghrsc->irq; + } + + ret = of_property_read_u64_index(pdev->dev.of_node, "reg", idx, + &ghrsc->capid); + if (ret) { + dev_err(&pdev->dev, "Failed to get %s capid: %d\n", + idx ? "rx" : "tx", ret); + return ret; + } + + return 0; +} + +static int gunyah_rm_probe_tx_msgq(struct gunyah_rm *rm, + struct platform_device *pdev) +{ + int ret; + + rm->tx_ghrsc.type = GUNYAH_RESOURCE_TYPE_MSGQ_TX; + ret = gunyah_platform_probe_capability(pdev, 0, &rm->tx_ghrsc); + if (ret) + return ret; + + enable_irq_wake(rm->tx_ghrsc.irq); + + return devm_request_irq(rm->dev, rm->tx_ghrsc.irq, gunyah_rm_tx, 0, + "gunyah_rm_tx", rm); +} + +static int gunyah_rm_probe_rx_msgq(struct gunyah_rm *rm, + struct platform_device *pdev) +{ + int ret; + + rm->rx_ghrsc.type = GUNYAH_RESOURCE_TYPE_MSGQ_RX; + ret = gunyah_platform_probe_capability(pdev, 1, &rm->rx_ghrsc); + if (ret) + return ret; + + enable_irq_wake(rm->rx_ghrsc.irq); + + return devm_request_threaded_irq(rm->dev, rm->rx_ghrsc.irq, NULL, + gunyah_rm_rx, IRQF_ONESHOT, + "gunyah_rm_rx", rm); +} + +static int gunyah_rm_probe(struct platform_device *pdev) +{ + struct gunyah_rm *rm; + int ret; + + rm = devm_kzalloc(&pdev->dev, sizeof(*rm), GFP_KERNEL); + if (!rm) + return -ENOMEM; + + platform_set_drvdata(pdev, rm); + rm->dev = &pdev->dev; + + mutex_init(&rm->send_lock); + init_completion(&rm->send_ready); + BLOCKING_INIT_NOTIFIER_HEAD(&rm->nh); + xa_init_flags(&rm->call_xarray, XA_FLAGS_ALLOC); + + device_init_wakeup(&pdev->dev, true); + + ret = gunyah_rm_probe_tx_msgq(rm, pdev); + if (ret) + return ret; + /* assume RM is ready to receive messages from us */ + complete(&rm->send_ready); + + ret = gunyah_rm_probe_rx_msgq(rm, pdev); + if (ret) + return ret; + + return 0; +} + +static const struct of_device_id gunyah_rm_of_match[] = { + { .compatible = "gunyah-resource-manager" }, + {} +}; +MODULE_DEVICE_TABLE(of, gunyah_rm_of_match); + +static struct platform_driver gunyah_rm_driver = { + .probe = gunyah_rm_probe, + .driver = { + .name = "gunyah_rsc_mgr", + .of_match_table = gunyah_rm_of_match, + }, +}; +module_platform_driver(gunyah_rm_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Resource Manager Driver"); diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h new file mode 100644 index 0000000000000..48b69dbf2190b --- /dev/null +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#ifndef __GUNYAH_RSC_MGR_PRIV_H +#define __GUNYAH_RSC_MGR_PRIV_H + +#include +#include +#include + +#define GUNYAH_VMID_INVAL U16_MAX + +struct gunyah_rm; + +int gunyah_rm_notifier_register(struct gunyah_rm *rm, + struct notifier_block *nb); +int gunyah_rm_notifier_unregister(struct gunyah_rm *rm, + struct notifier_block *nb); + + +int gunyah_rm_call(struct gunyah_rm *rsc_mgr, u32 message_id, + const void *req_buf, size_t req_buf_size, void **resp_buf, + size_t *resp_buf_size); + +#endif From patchwork Thu Feb 22 23:16:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568228 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CDE3C54798 for ; Thu, 22 Feb 2024 23:16:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DB3A6B0087; Thu, 22 Feb 2024 18:16:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 312D76B0088; Thu, 22 Feb 2024 18:16:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13EA16B0089; Thu, 22 Feb 2024 18:16:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EA4486B0087 for ; Thu, 22 Feb 2024 18:16:42 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BA252140A46 for ; Thu, 22 Feb 2024 23:16:42 +0000 (UTC) X-FDA: 81821001444.16.E70AB7D Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf25.hostedemail.com (Postfix) with ESMTP id B7D6AA000F for ; Thu, 22 Feb 2024 23:16:40 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=c4FHSPiO; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf25.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643800; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AzSoWsq1GRLYsvZhrkELU+C2/mkvSPT+9OER08NcI0Q=; b=m71suxRHyhkgyb+t5F0pVGyU93hpTkz7+TqUUz94faaNpC79OyvTVJ7IOS7EW8e5XqmfpK L/F9w05Zl5eI/djYbjIBaoeT0Gpvs1QE7W3oDcF3Y2KzkgJqKQeq7r4X/BdDb9RxtJUE8X BhbBEjNOB07hQgr4fhRmiAI+nSaJP20= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=c4FHSPiO; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf25.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643800; a=rsa-sha256; cv=none; b=nv9PJLCxAJqS8P8TXzicMJomiw6UU7vUGONVkChCDVmq5j6jBc4O87XxILKpJK5B4r+Saz etoA1ZBGiGGdijKpFo0utmTVPMPTPjaW6JI2mow8q5W/cBTxz745atfrWdzkKTt3sM9Z/h Z06NhEfUsxJGQwt2s+2SxGC8LY97ZBg= Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLuSH7019915; Thu, 22 Feb 2024 23:16:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=AzSoWsq1GRLYsvZhrkELU+C2/mkvSPT+9OER08NcI0Q =; b=c4FHSPiOPiOFSQRkfIq3ElvxtYvbsbY9X5mAgPHqCmepP7sWjVMIPmjTuAO bHt463IAhgxIXsjyUP7d0eyRzO/zWVlFKcvBt5LmoPPCZw8gHEkesNU9JyITQXec 0ptjS0zbYkbbjHj/xuiAtbgpJLroXh6lKCraOKOHgsPBHnGml9FScIPrzGN/PMBB 3PCrxfpbBpILUpAt2+PE54fs02/WnA5ftQDOWvyLJqLWf6LoU0cJwDKd4BBl+8Ae 7xPM6MPq3/iXmXwfvKdN00v62Ftci/4C8JA0cZ0X4JLq+jfqjcFsaq0ox8LBs/Rj tRcHxwZBYtvUa8c0YlYyQDYCCuA== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3weedkr5ev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:32 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGV6k027681 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:31 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:31 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:31 -0800 Subject: [PATCH v17 08/35] gunyah: vm_mgr: Introduce basic VM Manager MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-8-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: KJ3uDWdFbCfNSF2X6ZwJ4I5DtSATNaar X-Proofpoint-GUID: KJ3uDWdFbCfNSF2X6ZwJ4I5DtSATNaar X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220178 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B7D6AA000F X-Stat-Signature: am6exjfmntojoufk1ieti65a7w9tzr9f X-HE-Tag: 1708643800-578620 X-HE-Meta: U2FsdGVkX19iL2HAugWlmQfU4y/zswhBkXKfV2O913CO/mDla3quOsr71UhX5VZhIo4wAMUJKPeIPeoBxj2bhKyEl2gQ0irzbI47MNPlGZB3C8KZdaoNrv9miSxfiN1sGPJELZ46ySlzxNxG47TEnx1TcchUjif/mQj0XjeQf+V2D98XKulFvF0Hwcy+aDDCqiWibxmUUg2FtfVxQjHJqvUH1IVnT3pg59smkT1AI5CZMiHUCqNnBsYOocUwHLVMnh48p5MKf5TqusKt+Qz+j4hXnUq3YBGWpRqaztdcFUqBB6WFZDHERbCPsA1gSnRHR6dPgWHK8QyQZAGBe2H9VaDl+IVsGZqLFmT4L8X+E2E5hZ52n5/EE9zz9Hecm8Ai3CRQtGqtg5Bq9oeVG0TcOY90s3680WdlqeLVhhCjsCWJxnv2yRxOJm+F5YR+zt71/eghfljTDENggUsdGiWx3dom5wccyMalLIQoB7iGpho9gvYbpFeqEpJceD0WcLzV86bKukvXzipJjXk3xe+oHlpbJ7aEMnyQc0BIXYsU0NM5vy/MtQfFGhZcQyvGBwisWkyR316ulB1sYs+B41tOoOgCInCcsaEzPORAOhUMvO/KZU3mqkf5fn7x4xMkyYvK9LUcpjp44Vh9AonMIaDxGQZdt1qsTWb6qTafpfhtV0TLapUJuUsuRMYQoXtpcRPD/vNXq20Zg3pqAndR5BkGa0lpVhierPuhjI5wBWs6DmvkvgxPsExol8chYsIg6a/nKO3Dp1HTe5x+PYZ9TRQq1ImCSLsQ0lCkKA4uQtACUHmpPENsxQLyw6FxsY1o+UWMCThCJ9KegjziG4/cR7l9eNbqX4YZESS1gA3NyDMbCSz8/yh12NnzTZ/F0PVX6adp1WjzBciFr5tZ0m6dsnffjKrWNycRCO75UvnaUA1oidUv55pEcYkWRs7hcLLkbR8GaBBKH91l0LJrgW1cXP0 Tzj+NAKc NQ0XaFYZSOq8qbS+XA4TwHDIH1ofaCoE83RB/ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Gunyah VM manager is a kernel moduel which exposes an interface to userspace to load, run, and interact with other Gunyah virtual machines. The interface is a character device at /dev/gunyah. Add a basic VM manager driver. Upcoming patches will add more ioctls into this driver. Reviewed-by: Srinivas Kandagatla Reviewed-by: Alex Elder Co-developed-by: Prakruthi Deepak Heragu Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- Documentation/userspace-api/ioctl/ioctl-number.rst | 1 + drivers/virt/gunyah/Makefile | 2 +- drivers/virt/gunyah/rsc_mgr.c | 50 +++++++++++- drivers/virt/gunyah/rsc_mgr.h | 2 + drivers/virt/gunyah/vm_mgr.c | 94 ++++++++++++++++++++++ drivers/virt/gunyah/vm_mgr.h | 28 +++++++ include/uapi/linux/gunyah.h | 23 ++++++ 7 files changed, 198 insertions(+), 2 deletions(-) diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst index 457e16f06e04d..149e3899ad785 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -136,6 +136,7 @@ Code Seq# Include File Comments 'F' DD video/sstfb.h conflict! 'G' 00-3F drivers/misc/sgi-gru/grulib.h conflict! 'G' 00-0F xen/gntalloc.h, xen/gntdev.h conflict! +'G' 00-0F linux/gunyah.h conflict! 'H' 00-7F linux/hiddev.h conflict! 'H' 00-0F linux/hidraw.h conflict! 'H' 01 linux/mei.h conflict! diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index c2308389f5517..ceccbbe68b380 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -gunyah_rsc_mgr-y += rsc_mgr.o +gunyah_rsc_mgr-y += rsc_mgr.o vm_mgr.o obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o diff --git a/drivers/virt/gunyah/rsc_mgr.c b/drivers/virt/gunyah/rsc_mgr.c index 4ac946da0ca7f..fb0efe68f0e22 100644 --- a/drivers/virt/gunyah/rsc_mgr.c +++ b/drivers/virt/gunyah/rsc_mgr.c @@ -10,8 +10,10 @@ #include #include #include +#include #include "rsc_mgr.h" +#include "vm_mgr.h" /* clang-format off */ #define RM_RPC_API_VERSION_MASK GENMASK(3, 0) @@ -118,6 +120,7 @@ struct gunyah_rm_message { * @send_lock: synchronization to allow only one request to be sent at a time * @send_ready: completed when we know Tx message queue can take more messages * @nh: notifier chain for clients interested in RM notification messages + * @miscdev: /dev/gunyah */ struct gunyah_rm { struct device *dev; @@ -133,6 +136,8 @@ struct gunyah_rm { struct mutex send_lock; struct completion send_ready; struct blocking_notifier_head nh; + + struct miscdevice miscdev; }; /** @@ -613,6 +618,36 @@ int gunyah_rm_notifier_unregister(struct gunyah_rm *rm, } EXPORT_SYMBOL_GPL(gunyah_rm_notifier_unregister); +struct device *gunyah_rm_get(struct gunyah_rm *rm) +{ + return get_device(rm->miscdev.this_device); +} +EXPORT_SYMBOL_GPL(gunyah_rm_get); + +void gunyah_rm_put(struct gunyah_rm *rm) +{ + put_device(rm->miscdev.this_device); +} +EXPORT_SYMBOL_GPL(gunyah_rm_put); + +static long gunyah_dev_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg) +{ + struct miscdevice *miscdev = filp->private_data; + struct gunyah_rm *rm = container_of(miscdev, struct gunyah_rm, miscdev); + + return gunyah_dev_vm_mgr_ioctl(rm, cmd, arg); +} + +static const struct file_operations gunyah_dev_fops = { + /* clang-format off */ + .owner = THIS_MODULE, + .unlocked_ioctl = gunyah_dev_ioctl, + .compat_ioctl = compat_ptr_ioctl, + .llseek = noop_llseek, + /* clang-format on */ +}; + static int gunyah_platform_probe_capability(struct platform_device *pdev, int idx, struct gunyah_resource *ghrsc) @@ -699,7 +734,19 @@ static int gunyah_rm_probe(struct platform_device *pdev) if (ret) return ret; - return 0; + rm->miscdev.parent = &pdev->dev; + rm->miscdev.name = "gunyah"; + rm->miscdev.minor = MISC_DYNAMIC_MINOR; + rm->miscdev.fops = &gunyah_dev_fops; + + return misc_register(&rm->miscdev); +} + +static void gunyah_rm_remove(struct platform_device *pdev) +{ + struct gunyah_rm *rm = platform_get_drvdata(pdev); + + misc_deregister(&rm->miscdev); } static const struct of_device_id gunyah_rm_of_match[] = { @@ -710,6 +757,7 @@ MODULE_DEVICE_TABLE(of, gunyah_rm_of_match); static struct platform_driver gunyah_rm_driver = { .probe = gunyah_rm_probe, + .remove_new = gunyah_rm_remove, .driver = { .name = "gunyah_rsc_mgr", .of_match_table = gunyah_rm_of_match, diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index 48b69dbf2190b..21318ef25040c 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -17,6 +17,8 @@ int gunyah_rm_notifier_register(struct gunyah_rm *rm, struct notifier_block *nb); int gunyah_rm_notifier_unregister(struct gunyah_rm *rm, struct notifier_block *nb); +struct device *gunyah_rm_get(struct gunyah_rm *rm); +void gunyah_rm_put(struct gunyah_rm *rm); int gunyah_rm_call(struct gunyah_rm *rsc_mgr, u32 message_id, diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c new file mode 100644 index 0000000000000..e9dff733e35ef --- /dev/null +++ b/drivers/virt/gunyah/vm_mgr.c @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) "gunyah_vm_mgr: " fmt + +#include +#include +#include +#include + +#include + +#include "rsc_mgr.h" +#include "vm_mgr.h" + +static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) +{ + struct gunyah_vm *ghvm; + + ghvm = kzalloc(sizeof(*ghvm), GFP_KERNEL); + if (!ghvm) + return ERR_PTR(-ENOMEM); + + ghvm->parent = gunyah_rm_get(rm); + ghvm->rm = rm; + + return ghvm; +} + +static int gunyah_vm_release(struct inode *inode, struct file *filp) +{ + struct gunyah_vm *ghvm = filp->private_data; + + gunyah_rm_put(ghvm->rm); + kfree(ghvm); + return 0; +} + +static const struct file_operations gunyah_vm_fops = { + .owner = THIS_MODULE, + .release = gunyah_vm_release, + .llseek = noop_llseek, +}; + +static long gunyah_dev_ioctl_create_vm(struct gunyah_rm *rm, unsigned long arg) +{ + struct gunyah_vm *ghvm; + struct file *file; + int fd, err; + + /* arg reserved for future use. */ + if (arg) + return -EINVAL; + + ghvm = gunyah_vm_alloc(rm); + if (IS_ERR(ghvm)) + return PTR_ERR(ghvm); + + fd = get_unused_fd_flags(O_CLOEXEC); + if (fd < 0) { + err = fd; + goto err_destroy_vm; + } + + file = anon_inode_getfile("gunyah-vm", &gunyah_vm_fops, ghvm, O_RDWR); + if (IS_ERR(file)) { + err = PTR_ERR(file); + goto err_put_fd; + } + + fd_install(fd, file); + + return fd; + +err_put_fd: + put_unused_fd(fd); +err_destroy_vm: + gunyah_rm_put(ghvm->rm); + kfree(ghvm); + return err; +} + +long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, + unsigned long arg) +{ + switch (cmd) { + case GUNYAH_CREATE_VM: + return gunyah_dev_ioctl_create_vm(rm, arg); + default: + return -ENOTTY; + } +} diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h new file mode 100644 index 0000000000000..50790d4026765 --- /dev/null +++ b/drivers/virt/gunyah/vm_mgr.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _GUNYAH_VM_MGR_PRIV_H +#define _GUNYAH_VM_MGR_PRIV_H + +#include + +#include + +#include "rsc_mgr.h" + +long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, + unsigned long arg); + +/** + * struct gunyah_vm - Main representation of a Gunyah Virtual machine + * @rm: Pointer to the resource manager struct to make RM calls + * @parent: For logging + */ +struct gunyah_vm { + struct gunyah_rm *rm; + struct device *parent; +}; + +#endif diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h new file mode 100644 index 0000000000000..ac338ec4b85dd --- /dev/null +++ b/include/uapi/linux/gunyah.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ +/* + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _UAPI_LINUX_GUNYAH_H +#define _UAPI_LINUX_GUNYAH_H + +/* + * Userspace interface for /dev/gunyah - gunyah based virtual machine + */ + +#include +#include + +#define GUNYAH_IOCTL_TYPE 'G' + +/* + * ioctls for /dev/gunyah fds: + */ +#define GUNYAH_CREATE_VM _IO(GUNYAH_IOCTL_TYPE, 0x0) /* Returns a Gunyah VM fd */ + +#endif From patchwork Thu Feb 22 23:16:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1305EC47DD9 for ; Thu, 22 Feb 2024 23:17:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1CF56B0089; Thu, 22 Feb 2024 18:16:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A4556B008A; Thu, 22 Feb 2024 18:16:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75DD66B008C; Thu, 22 Feb 2024 18:16:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 57A086B0089 for ; Thu, 22 Feb 2024 18:16:44 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 27538810A2 for ; Thu, 22 Feb 2024 23:16:44 +0000 (UTC) X-FDA: 81821001528.05.DBFAB44 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf23.hostedemail.com (Postfix) with ESMTP id 1081414000E for ; Thu, 22 Feb 2024 23:16:41 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=ixa7SQjr; spf=pass (imf23.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643802; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Eos+4QsQMLDq3hpbjG+KYOjvUTdDf9AT0ygZFi6k3VQ=; b=WtuQRyBy15voPSaVt2VH7wDNqFBo+zLIlnMUgqn0n6rVBA61PXXPlKRRWmwB4pdp2bTBaY 4dNHh296Fu0QzT0K6NHTm6tQWU72vR3fHRaGu1ie6Pwnv3uNY9xuYsTmZlIVKUvygXksRI c+3GJX0Ded82f9EL/yBgah8cpya61Nc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643802; a=rsa-sha256; cv=none; b=dDmia27a3MoXbCb/BRhrmqVJJgTw86w5bYkhAPvBxMcw/9i3LH/a93B1PjaMYrUfjaAIAi CS9v6SRRVGP7oiDtOQIKmIEnqO5yhsj2r7Cx+LNXaif2NIU0zhMY9+5tBXr4OyV37yzQdJ 22eq72U2igLaCrsFmtUYS5JAj9+zda4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=ixa7SQjr; spf=pass (imf23.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MKvtBL022871; Thu, 22 Feb 2024 23:16:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=Eos+4QsQMLDq3hpbjG+KYOjvUTdDf9AT0ygZFi6k3VQ =; b=ixa7SQjrNI3DdR2pR4MMeNYLeyAYYKLiJdP828y24kfY64YmZB/57puJRW5 hT2TX4gQoxuc2VDhEB9jK/G6NKUm8dtZHKuApQlvdQbxbL0XEuAYhjWwYDQqrhHG EZ6ukzanPUV0IbRkGUpx/rq2ISuEG4xwWdTWuTel49WUe6qlNrA20V7vKZ+oHT6D vyXQnEQbMRqOKuhbqe/DWZb0m0zqLO5uod2NXrOoY/BlA/CYDA82fqjMyKkxvmoD OGatytBGvNw/4vOUEXHimcZ91nd2v/8SFqa5hxHfpLnT9UOuI9e2+kAunhfG/vSe sAgPzS8eQmo/o4PlzOjoi/nyHEA== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we97tgf89-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:33 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGW8W025534 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:32 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:31 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:32 -0800 Subject: [PATCH v17 09/35] gunyah: rsc_mgr: Add VM lifecycle RPC MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-9-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: hxYLiD4vprUOacEBPL7Ym-_TB4nrWIcz X-Proofpoint-ORIG-GUID: hxYLiD4vprUOacEBPL7Ym-_TB4nrWIcz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 adultscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: 1081414000E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: tyxzqxayafy6b1sd96xmwksjuhgym7m9 X-HE-Tag: 1708643801-76676 X-HE-Meta: U2FsdGVkX1/a9SgZF2j+wkjEDoA0dgAhACbOOJ7vpUWdENvNEzLPv9BQ2r9zBUx/BIgPq/ylJDtizZrehflMt1DpX6xd1AjHVwl4DqzsIOjRhLJKiSbC4MIcr9Cdi+dwkIKuHlS3empZHuENrL6PzS1s4SaF33mn1bxFnuJ892eIDya947icJF6e/Wy2l+23rLEillKrSZ18t6V1A4hWpNVy6bgCWaudTdQ9Yzw/wfl22GWBXd4ZD/0eucV/5AKCEuGUn/Gff7MmfOVuk0cJHCeX1A0rAfQrOkMLmUgT3bMhN1OWNggq8r/z0E1xvz6oiEk7spWJpjiOqHkDEWdo8jfYWizurwCwib1he5OVVFv8CBwPYb3TxdREzKGfSrQd/Zhszaihnfhcue51Ou/PzkuAhM3B9Mq4/3fXkWOWKFFoqtWpYiI8blIB0GXiRsNzTZzUN3btHFCG7bHUz0GxlXYW1V+K67D0tS0tfxrBVx6P0Kpvhxh3BO2nDwC8EmXGYdhEC7W4E+oFuCyaYfutJC+sdzSq4adCdD1q+cPDCG2E9TdjE0orVuqD2RP2n6c+lC0L4bS/2KSfvVjsf8UmaHDtjWDlZv/zfhbanSGvkJSBhGsqHJl+mPEHTcOueAB0i3A05f/V6ttsvAgmRIqrfM5/DAdk7j/KOS+b7oygGQfrs01MIC6h0MaOIa1Fqw2fqzZ1PraXVZssXxoFZRT3JmHkInIb9s5NLjCgL4GSpSaw5oIwNt6uxF64gHtjvNStbNfQete9cSgguFBQDerCX3nMUItuBO79NumRZwB9D/g3eyJEeIawozU9//sY1Y+fC9VUdjVLuWK9BebF66HsMIT+pvNMUiKnisTYajvxZKwhDDroVgoOUZMb7enPGrHsVmrJFfRS7eotTvmwtk5s1zGvQEUt4y7mpYW5eLCWZSgwGBcEFUCz05ZIXMSQcaWwD0CIro/EYUt4pRVgG8G KVBib37s vuQDWuZJGNC1BQMP1Lft0dP9BcaN9BbpsxNAf X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add Gunyah Resource Manager RPC interfaces to launch an unauthenticated virtual machine. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- drivers/virt/gunyah/Makefile | 2 +- drivers/virt/gunyah/rsc_mgr.h | 78 ++++++++++++ drivers/virt/gunyah/rsc_mgr_rpc.c | 248 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 327 insertions(+), 1 deletion(-) diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index ceccbbe68b380..47f1fae5419bf 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -gunyah_rsc_mgr-y += rsc_mgr.o vm_mgr.o +gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index 21318ef25040c..205b9ea735e53 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -20,6 +20,84 @@ int gunyah_rm_notifier_unregister(struct gunyah_rm *rm, struct device *gunyah_rm_get(struct gunyah_rm *rm); void gunyah_rm_put(struct gunyah_rm *rm); +struct gunyah_rm_vm_exited_payload { + __le16 vmid; + __le16 exit_type; + __le32 exit_reason_size; + u8 exit_reason[]; +} __packed; + +enum gunyah_rm_notification_id { + /* clang-format off */ + GUNYAH_RM_NOTIFICATION_VM_EXITED = 0x56100001, + GUNYAH_RM_NOTIFICATION_VM_STATUS = 0x56100008, + /* clang-format on */ +}; + +enum gunyah_rm_vm_status { + /* clang-format off */ + GUNYAH_RM_VM_STATUS_NO_STATE = 0, + GUNYAH_RM_VM_STATUS_INIT = 1, + GUNYAH_RM_VM_STATUS_READY = 2, + GUNYAH_RM_VM_STATUS_RUNNING = 3, + GUNYAH_RM_VM_STATUS_PAUSED = 4, + GUNYAH_RM_VM_STATUS_LOAD = 5, + GUNYAH_RM_VM_STATUS_AUTH = 6, + GUNYAH_RM_VM_STATUS_INIT_FAILED = 8, + GUNYAH_RM_VM_STATUS_EXITED = 9, + GUNYAH_RM_VM_STATUS_RESETTING = 10, + GUNYAH_RM_VM_STATUS_RESET = 11, + /* clang-format on */ +}; + +struct gunyah_rm_vm_status_payload { + __le16 vmid; + u16 reserved; + u8 vm_status; + u8 os_status; + __le16 app_status; +} __packed; + +int gunyah_rm_alloc_vmid(struct gunyah_rm *rm, u16 vmid); +int gunyah_rm_dealloc_vmid(struct gunyah_rm *rm, u16 vmid); +int gunyah_rm_vm_reset(struct gunyah_rm *rm, u16 vmid); +int gunyah_rm_vm_start(struct gunyah_rm *rm, u16 vmid); +int gunyah_rm_vm_stop(struct gunyah_rm *rm, u16 vmid); + +enum gunyah_rm_vm_auth_mechanism { + /* clang-format off */ + GUNYAH_RM_VM_AUTH_NONE = 0, + GUNYAH_RM_VM_AUTH_QCOM_PIL_ELF = 1, + GUNYAH_RM_VM_AUTH_QCOM_ANDROID_PVM = 2, + /* clang-format on */ +}; + +int gunyah_rm_vm_configure(struct gunyah_rm *rm, u16 vmid, + enum gunyah_rm_vm_auth_mechanism auth_mechanism, + u32 mem_handle, u64 image_offset, u64 image_size, + u64 dtb_offset, u64 dtb_size); +int gunyah_rm_vm_init(struct gunyah_rm *rm, u16 vmid); + +struct gunyah_rm_hyp_resource { + u8 type; + u8 reserved; + __le16 partner_vmid; + __le32 resource_handle; + __le32 resource_label; + __le64 cap_id; + __le32 virq_handle; + __le32 virq; + __le64 base; + __le64 size; +} __packed; + +struct gunyah_rm_hyp_resources { + __le32 n_entries; + struct gunyah_rm_hyp_resource entries[]; +} __packed; + +int gunyah_rm_get_hyp_resources(struct gunyah_rm *rm, u16 vmid, + struct gunyah_rm_hyp_resources **resources); int gunyah_rm_call(struct gunyah_rm *rsc_mgr, u32 message_id, const void *req_buf, size_t req_buf_size, void **resp_buf, diff --git a/drivers/virt/gunyah/rsc_mgr_rpc.c b/drivers/virt/gunyah/rsc_mgr_rpc.c new file mode 100644 index 0000000000000..c2f4ccae8f3bc --- /dev/null +++ b/drivers/virt/gunyah/rsc_mgr_rpc.c @@ -0,0 +1,248 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include + +#include "rsc_mgr.h" + +/* Message IDs: VM Management */ +/* clang-format off */ +#define GUNYAH_RM_RPC_VM_ALLOC_VMID 0x56000001 +#define GUNYAH_RM_RPC_VM_DEALLOC_VMID 0x56000002 +#define GUNYAH_RM_RPC_VM_START 0x56000004 +#define GUNYAH_RM_RPC_VM_STOP 0x56000005 +#define GUNYAH_RM_RPC_VM_RESET 0x56000006 +#define GUNYAH_RM_RPC_VM_CONFIG_IMAGE 0x56000009 +#define GUNYAH_RM_RPC_VM_INIT 0x5600000B +#define GUNYAH_RM_RPC_VM_GET_HYP_RESOURCES 0x56000020 +/* clang-format on */ + +struct gunyah_rm_vm_common_vmid_req { + __le16 vmid; + __le16 _padding; +} __packed; + +/* Call: VM_ALLOC */ +struct gunyah_rm_vm_alloc_vmid_resp { + __le16 vmid; + __le16 _padding; +} __packed; + +/* Call: VM_STOP */ +#define GUNYAH_RM_VM_STOP_FLAG_FORCE_STOP BIT(0) + +#define GUNYAH_RM_VM_STOP_REASON_FORCE_STOP 3 + +struct gunyah_rm_vm_stop_req { + __le16 vmid; + u8 flags; + u8 _padding; + __le32 stop_reason; +} __packed; + +/* Call: VM_CONFIG_IMAGE */ +struct gunyah_rm_vm_config_image_req { + __le16 vmid; + __le16 auth_mech; + __le32 mem_handle; + __le64 image_offset; + __le64 image_size; + __le64 dtb_offset; + __le64 dtb_size; +} __packed; + +/* + * Several RM calls take only a VMID as a parameter and give only standard + * response back. Deduplicate boilerplate code by using this common call. + */ +static int gunyah_rm_common_vmid_call(struct gunyah_rm *rm, u32 message_id, + u16 vmid) +{ + struct gunyah_rm_vm_common_vmid_req req_payload = { + .vmid = cpu_to_le16(vmid), + }; + + return gunyah_rm_call(rm, message_id, &req_payload, sizeof(req_payload), + NULL, NULL); +} + +/** + * gunyah_rm_alloc_vmid() - Allocate a new VM in Gunyah. Returns the VM identifier. + * @rm: Handle to a Gunyah resource manager + * @vmid: Use 0 to dynamically allocate a VM. A reserved VMID can be supplied + * to request allocation of a platform-defined VM. + * + * Return: the allocated VMID or negative value on error + */ +int gunyah_rm_alloc_vmid(struct gunyah_rm *rm, u16 vmid) +{ + struct gunyah_rm_vm_common_vmid_req req_payload = { + .vmid = cpu_to_le16(vmid), + }; + struct gunyah_rm_vm_alloc_vmid_resp *resp_payload; + size_t resp_size; + void *resp; + int ret; + + ret = gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_ALLOC_VMID, &req_payload, + sizeof(req_payload), &resp, &resp_size); + if (ret) + return ret; + + if (!vmid) { + resp_payload = resp; + ret = le16_to_cpu(resp_payload->vmid); + kfree(resp); + } + + return ret; +} +ALLOW_ERROR_INJECTION(gunyah_rm_alloc_vmid, ERRNO); + +/** + * gunyah_rm_dealloc_vmid() - Dispose of a VMID + * @rm: Handle to a Gunyah resource manager + * @vmid: VM identifier allocated with gunyah_rm_alloc_vmid + */ +int gunyah_rm_dealloc_vmid(struct gunyah_rm *rm, u16 vmid) +{ + return gunyah_rm_common_vmid_call(rm, GUNYAH_RM_RPC_VM_DEALLOC_VMID, + vmid); +} +ALLOW_ERROR_INJECTION(gunyah_rm_dealloc_vmid, ERRNO); + +/** + * gunyah_rm_vm_reset() - Reset a VM's resources + * @rm: Handle to a Gunyah resource manager + * @vmid: VM identifier allocated with gunyah_rm_alloc_vmid + * + * As part of tearing down the VM, request RM to clean up all the VM resources + * associated with the VM. Only after this, Linux can clean up all the + * references it maintains to resources. + */ +int gunyah_rm_vm_reset(struct gunyah_rm *rm, u16 vmid) +{ + return gunyah_rm_common_vmid_call(rm, GUNYAH_RM_RPC_VM_RESET, vmid); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_reset, ERRNO); + +/** + * gunyah_rm_vm_start() - Move a VM into "ready to run" state + * @rm: Handle to a Gunyah resource manager + * @vmid: VM identifier allocated with gunyah_rm_alloc_vmid + * + * On VMs which use proxy scheduling, vcpu_run is needed to actually run the VM. + * On VMs which use Gunyah's scheduling, the vCPUs start executing in accordance with Gunyah + * scheduling policies. + */ +int gunyah_rm_vm_start(struct gunyah_rm *rm, u16 vmid) +{ + return gunyah_rm_common_vmid_call(rm, GUNYAH_RM_RPC_VM_START, vmid); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_start, ERRNO); + +/** + * gunyah_rm_vm_stop() - Send a request to Resource Manager VM to forcibly stop a VM. + * @rm: Handle to a Gunyah resource manager + * @vmid: VM identifier allocated with gunyah_rm_alloc_vmid + */ +int gunyah_rm_vm_stop(struct gunyah_rm *rm, u16 vmid) +{ + struct gunyah_rm_vm_stop_req req_payload = { + .vmid = cpu_to_le16(vmid), + .flags = GUNYAH_RM_VM_STOP_FLAG_FORCE_STOP, + .stop_reason = cpu_to_le32(GUNYAH_RM_VM_STOP_REASON_FORCE_STOP), + }; + + return gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_STOP, &req_payload, + sizeof(req_payload), NULL, NULL); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_stop, ERRNO); + +/** + * gunyah_rm_vm_configure() - Prepare a VM to start and provide the common + * configuration needed by RM to configure a VM + * @rm: Handle to a Gunyah resource manager + * @vmid: VM identifier allocated with gunyah_rm_alloc_vmid + * @auth_mechanism: Authentication mechanism used by resource manager to verify + * the virtual machine + * @mem_handle: Handle to a previously shared memparcel that contains all parts + * of the VM image subject to authentication. + * @image_offset: Start address of VM image, relative to the start of memparcel + * @image_size: Size of the VM image + * @dtb_offset: Start address of the devicetree binary with VM configuration, + * relative to start of memparcel. + * @dtb_size: Maximum size of devicetree binary. + */ +int gunyah_rm_vm_configure(struct gunyah_rm *rm, u16 vmid, + enum gunyah_rm_vm_auth_mechanism auth_mechanism, + u32 mem_handle, u64 image_offset, u64 image_size, + u64 dtb_offset, u64 dtb_size) +{ + struct gunyah_rm_vm_config_image_req req_payload = { + .vmid = cpu_to_le16(vmid), + .auth_mech = cpu_to_le16(auth_mechanism), + .mem_handle = cpu_to_le32(mem_handle), + .image_offset = cpu_to_le64(image_offset), + .image_size = cpu_to_le64(image_size), + .dtb_offset = cpu_to_le64(dtb_offset), + .dtb_size = cpu_to_le64(dtb_size), + }; + + return gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_CONFIG_IMAGE, &req_payload, + sizeof(req_payload), NULL, NULL); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_configure, ERRNO); + +/** + * gunyah_rm_vm_init() - Move the VM to initialized state. + * @rm: Handle to a Gunyah resource manager + * @vmid: VM identifier + * + * RM will allocate needed resources for the VM. + */ +int gunyah_rm_vm_init(struct gunyah_rm *rm, u16 vmid) +{ + return gunyah_rm_common_vmid_call(rm, GUNYAH_RM_RPC_VM_INIT, vmid); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_init, ERRNO); + +/** + * gunyah_rm_get_hyp_resources() - Retrieve hypervisor resources (capabilities) associated with a VM + * @rm: Handle to a Gunyah resource manager + * @vmid: VMID of the other VM to get the resources of + * @resources: Set by gunyah_rm_get_hyp_resources and contains the returned hypervisor resources. + * Caller must free the resources pointer if successful. + */ +int gunyah_rm_get_hyp_resources(struct gunyah_rm *rm, u16 vmid, + struct gunyah_rm_hyp_resources **resources) +{ + struct gunyah_rm_vm_common_vmid_req req_payload = { + .vmid = cpu_to_le16(vmid), + }; + struct gunyah_rm_hyp_resources *resp; + size_t resp_size; + int ret; + + ret = gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_GET_HYP_RESOURCES, + &req_payload, sizeof(req_payload), (void **)&resp, + &resp_size); + if (ret) + return ret; + + if (!resp_size) + return -EBADMSG; + + if (resp_size < struct_size(resp, entries, 0) || + resp_size != + struct_size(resp, entries, le32_to_cpu(resp->n_entries))) { + kfree(resp); + return -EBADMSG; + } + + *resources = resp; + return 0; +} +ALLOW_ERROR_INJECTION(gunyah_rm_get_hyp_resources, ERRNO); From patchwork Thu Feb 22 23:16:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97167C54E49 for ; Thu, 22 Feb 2024 23:17:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEF7A6B0093; Thu, 22 Feb 2024 18:16:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BF01D6B008C; Thu, 22 Feb 2024 18:16:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81E306B0093; Thu, 22 Feb 2024 18:16:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5AEE76B008C for ; Thu, 22 Feb 2024 18:16:45 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 08356140DB1 for ; Thu, 22 Feb 2024 23:16:44 +0000 (UTC) X-FDA: 81821001528.04.6114345 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf11.hostedemail.com (Postfix) with ESMTP id BDB0C40005 for ; Thu, 22 Feb 2024 23:16:41 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=Yc5tWIN0; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643801; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AqRBgoMwHFsPe/avimmGMJYvOaG0LLtyLOSPpj0/UN8=; b=0WKBFRc5lb2K/GsE/wKvNxkZ2l/Gqe/TjAG7fNVhPFfuvz84AmsHZSanZbcEnS6tQD7eSY ImcGCBw2Y9Yk4fx5uo7TeSlmYNDuq25iSObEVGHCb+DuBKyd1LkS2MwhE/+xtEK3frHShw CxWzaIFT2IXefr6yG+eq80OwnFLqkpU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=Yc5tWIN0; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643801; a=rsa-sha256; cv=none; b=yqy4UCXC6wA00mfg5WWVqz7CDKhXcaBgkhCn10nbHwgQANlbWMMaZ8Q6Kmlv3OObfcJ5sP JDWbtWyCXK9DD3WOUckOlrdoPTHcs26I1JNyeUkQaoHSA2mZLkzlwhKDQWNrswSFCg/b1r NKtbgllbNR4+ZPQmlQwNCZf++2CgaVo= Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MM8tRX031789; Thu, 22 Feb 2024 23:16:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=AqRBgoMwHFsPe/avimmGMJYvOaG0LLtyLOSPpj0/UN8 =; b=Yc5tWIN0NHTjsiZi2As3t+YMG7By+G8XHo92TtZMZ2M87GrIBSJf72yTmsZ EUkpMVMsBhHSduA389li2zXF6nDfjHgt0vTTbFoUVOJDHpx/KufnueEnGomhWhRL 55OkbxVqaQBDRuO9HNWCaiWaXISNjktsOqsOJKHNDwl15NPzXPho7CDk7b7xcAIe Bsl26IAPp9xzVoeAQlaMBIQFtpdlD32Fd/KQxWLDaYsDKkHzlmahxrKE6xz03ORs 9NbtXXkBcpeSj8NSpr57I5Aio5thfqK/KGd1iuUIzkSkv7nd6A5uE0VwyDAPVuee +JSolBMh7XxdkHXpvZjpKjLSwtQ== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wea7csc2p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:33 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGXCk018212 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:33 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:32 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:33 -0800 Subject: [PATCH v17 10/35] gunyah: vm_mgr: Add VM start/stop MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-10-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: W4enkRgvHYvXwGyGPHcTI81Bm4TEY0_P X-Proofpoint-GUID: W4enkRgvHYvXwGyGPHcTI81Bm4TEY0_P X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 phishscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Stat-Signature: f3r17ptjrq8bt5d16mtbkryw87tewr34 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BDB0C40005 X-HE-Tag: 1708643801-922592 X-HE-Meta: U2FsdGVkX1+oldvqy1ss/JLb6fCiyj8TH8wyIvZVmMJDOo06JO0KxeKvJ4Qza1WyG0tZturLUZrr0nZhXnQfMt/dr22wgPrYZHeSR2/NZPBZDLezFDFUwNqc9VFrNMWEfyEjp7p1CPeT8oIhrCnyV1xiliRVaf+42JaKAdZsemUcahuzxgIAS9/Yx1vYFRTGix+dcUcQA6EY2XFLSN90NBvPNqTgr9zbCgGtwwURlfmsp7V9PW5R4mGMUy6DnMOiL9zMXmjhzp54pfTJSae6MxS+DPL1SVSehC69KwqyxhVhBFyXa25Iw9pvMhKID3h8nZ4GDAxW5drkFmI4FUZIyI3KNNvbLX8wEPVQPBu84/H/HamPkaaJLF7mr1Jbtw924mgKNEEJm57B8k/KzdkngiPN4juJ8r4ZTf0AFic9o9J4IF6kFE/dkDgFRBTz2peHbtZiNDsP7yFSlPNGmB6siSjkL6BIuCp33cvbbi5ilhSe8mc+szyUA32ErlhatAmqrhZ9OMDXBl07OQ12a+AlH9cJ41P3OCQUS7imY+wqlXSnul9JgeQgX6HcmQULTD7Nee3SNgAVK5rWQJWfp4cJMilmv0G3ulnMHxlT0O6R/CO6bJxXkY7fvrXMyhQZaZDNeQMq31KqNUGrt+jpQXe0u0qESJWMnIDVOSG2oL7AzgyiLOhCA9zQMWBDcpe3QJAlh8+IYohEaoobqg1/26B0sd2eeKbxWPp0AAZey53YIuOPCuMnmEdF46ID34BtV6J8RoAhGHDqw1m2A51lA6KzJvO32NutHDPIQEozTp88JMsyJz2d5MLon/o3tjU6TNeUIf/dnX3Gia31nXrUKnzJ35ZNpK6gWt+zxQQZlJZvxw4DfPD1Jx/UH39GI3/oqv5b+eXIRy0aC0Ke31uQ7TCfplBxP86xFLOr8P4N1v1sExkNIOkqzs4ajye+xs9tWAJ/vAFrzhc0zDUwT95aF+8 o9//rSSO jXlbWOZY/QPqaryb0UI2kAxJaDqhqEHoy1rqYlgQ98JHDtuc2H/fA9afiTie2BFmzBtOW4AJ7B+PzPNHtXB+oaP4oh88SiaJE40VigXsyyXpBgbjrBHHWNQ5S41oK9+igKFijYIdMxSWUZHYBYzlaKcbGNKXxdpDX+YfUaw9VF/R33jIiooqUmoMAqg6o6rhFN0vmbdSaA4MNyFqEsEfbOrh+daejkkhInDjkRJ4YFIEXDsd4ra2ekGFSd80NYY53qUbIY1SPL4RB9ArKKIdHuo5WiTiX2cbAV4mj1Zg4GfTqzFmDpofQOucEVM5+tEYhRQ7lPZwFYEOdiGAJJvZ+JCdgmMkjMrp2Ao7gQpzloThpQcLoziOUZQY+Bcns+SaF/PJNWxbii4GGCWZJP5VI6lO0rrYchUNx5oj6lHOlMqlgkX8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add ioctl to trigger the start of a Gunyah virtual machine. Subsequent commits will provide memory to the virtual machine and add ability to interact with the resources (capabilities) of the virtual machine. Although start of the virtual machine can be done implicitly on the first vCPU run for proxy-schedule virtual machines, there is a non-trivial number of calls to Gunyah: a more precise error can be given to userspace which calls VM_START without looking at kernel logs because userspace can detect that the VM start failed instead of "couldn't run the vCPU". Co-developed-by: Prakruthi Deepak Heragu Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- drivers/virt/gunyah/vm_mgr.c | 198 +++++++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/vm_mgr.h | 19 +++++ include/uapi/linux/gunyah.h | 5 ++ 3 files changed, 222 insertions(+) diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index e9dff733e35ef..364a53cad643e 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -15,6 +15,68 @@ #include "rsc_mgr.h" #include "vm_mgr.h" +static int gunyah_vm_rm_notification_status(struct gunyah_vm *ghvm, void *data) +{ + struct gunyah_rm_vm_status_payload *payload = data; + + if (le16_to_cpu(payload->vmid) != ghvm->vmid) + return NOTIFY_OK; + + /* All other state transitions are synchronous to a corresponding RM call */ + if (payload->vm_status == GUNYAH_RM_VM_STATUS_RESET) { + down_write(&ghvm->status_lock); + ghvm->vm_status = payload->vm_status; + up_write(&ghvm->status_lock); + wake_up(&ghvm->vm_status_wait); + } + + return NOTIFY_DONE; +} + +static int gunyah_vm_rm_notification_exited(struct gunyah_vm *ghvm, void *data) +{ + struct gunyah_rm_vm_exited_payload *payload = data; + + if (le16_to_cpu(payload->vmid) != ghvm->vmid) + return NOTIFY_OK; + + down_write(&ghvm->status_lock); + ghvm->vm_status = GUNYAH_RM_VM_STATUS_EXITED; + up_write(&ghvm->status_lock); + wake_up(&ghvm->vm_status_wait); + + return NOTIFY_DONE; +} + +static int gunyah_vm_rm_notification(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct gunyah_vm *ghvm = container_of(nb, struct gunyah_vm, nb); + + switch (action) { + case GUNYAH_RM_NOTIFICATION_VM_STATUS: + return gunyah_vm_rm_notification_status(ghvm, data); + case GUNYAH_RM_NOTIFICATION_VM_EXITED: + return gunyah_vm_rm_notification_exited(ghvm, data); + default: + return NOTIFY_OK; + } +} + +static void gunyah_vm_stop(struct gunyah_vm *ghvm) +{ + int ret; + + if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_RUNNING) { + ret = gunyah_rm_vm_stop(ghvm->rm, ghvm->vmid); + if (ret) + dev_warn(ghvm->parent, "Failed to stop VM: %d\n", ret); + } + + wait_event(ghvm->vm_status_wait, + ghvm->vm_status != GUNYAH_RM_VM_STATUS_RUNNING); +} + static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) { struct gunyah_vm *ghvm; @@ -24,14 +86,148 @@ static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) return ERR_PTR(-ENOMEM); ghvm->parent = gunyah_rm_get(rm); + ghvm->vmid = GUNYAH_VMID_INVAL; ghvm->rm = rm; + init_rwsem(&ghvm->status_lock); + init_waitqueue_head(&ghvm->vm_status_wait); + ghvm->vm_status = GUNYAH_RM_VM_STATUS_NO_STATE; + return ghvm; } +static int gunyah_vm_start(struct gunyah_vm *ghvm) +{ + int ret; + + down_write(&ghvm->status_lock); + if (ghvm->vm_status != GUNYAH_RM_VM_STATUS_NO_STATE) { + up_write(&ghvm->status_lock); + return 0; + } + + ghvm->nb.notifier_call = gunyah_vm_rm_notification; + ret = gunyah_rm_notifier_register(ghvm->rm, &ghvm->nb); + if (ret) + goto err; + + ret = gunyah_rm_alloc_vmid(ghvm->rm, 0); + if (ret < 0) { + gunyah_rm_notifier_unregister(ghvm->rm, &ghvm->nb); + goto err; + } + ghvm->vmid = ret; + ghvm->vm_status = GUNYAH_RM_VM_STATUS_LOAD; + + ret = gunyah_rm_vm_configure(ghvm->rm, ghvm->vmid, ghvm->auth, 0, 0, 0, + 0, 0); + if (ret) { + dev_warn(ghvm->parent, "Failed to configure VM: %d\n", ret); + goto err; + } + + ret = gunyah_rm_vm_init(ghvm->rm, ghvm->vmid); + if (ret) { + ghvm->vm_status = GUNYAH_RM_VM_STATUS_INIT_FAILED; + dev_warn(ghvm->parent, "Failed to initialize VM: %d\n", ret); + goto err; + } + ghvm->vm_status = GUNYAH_RM_VM_STATUS_READY; + + ret = gunyah_rm_vm_start(ghvm->rm, ghvm->vmid); + if (ret) { + dev_warn(ghvm->parent, "Failed to start VM: %d\n", ret); + goto err; + } + + ghvm->vm_status = GUNYAH_RM_VM_STATUS_RUNNING; + up_write(&ghvm->status_lock); + return ret; +err: + /* gunyah_vm_free will handle releasing resources and reclaiming memory */ + up_write(&ghvm->status_lock); + return ret; +} + +static int gunyah_vm_ensure_started(struct gunyah_vm *ghvm) +{ + int ret; + + ret = down_read_interruptible(&ghvm->status_lock); + if (ret) + return ret; + + /* Unlikely because VM is typically started */ + if (unlikely(ghvm->vm_status == GUNYAH_RM_VM_STATUS_NO_STATE)) { + up_read(&ghvm->status_lock); + ret = gunyah_vm_start(ghvm); + if (ret) + return ret; + ret = down_read_interruptible(&ghvm->status_lock); + if (ret) + return ret; + } + + /* Unlikely because VM is typically running */ + if (unlikely(ghvm->vm_status != GUNYAH_RM_VM_STATUS_RUNNING)) + ret = -ENODEV; + + up_read(&ghvm->status_lock); + return ret; +} + +static long gunyah_vm_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg) +{ + struct gunyah_vm *ghvm = filp->private_data; + long r; + + switch (cmd) { + case GUNYAH_VM_START: { + r = gunyah_vm_ensure_started(ghvm); + break; + } + default: + r = -ENOTTY; + break; + } + + return r; +} + static int gunyah_vm_release(struct inode *inode, struct file *filp) { struct gunyah_vm *ghvm = filp->private_data; + int ret; + + /** + * We might race with a VM exit notification, but that's ok: + * gh_rm_vm_stop() will just return right away. + */ + if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_RUNNING) + gunyah_vm_stop(ghvm); + + if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_EXITED || + ghvm->vm_status == GUNYAH_RM_VM_STATUS_READY || + ghvm->vm_status == GUNYAH_RM_VM_STATUS_INIT_FAILED) { + ret = gunyah_rm_vm_reset(ghvm->rm, ghvm->vmid); + /* clang-format off */ + if (!ret) + wait_event(ghvm->vm_status_wait, + ghvm->vm_status == GUNYAH_RM_VM_STATUS_RESET); + else + dev_err(ghvm->parent, "Failed to reset the vm: %d\n",ret); + /* clang-format on */ + } + + if (ghvm->vm_status > GUNYAH_RM_VM_STATUS_NO_STATE) { + gunyah_rm_notifier_unregister(ghvm->rm, &ghvm->nb); + + ret = gunyah_rm_dealloc_vmid(ghvm->rm, ghvm->vmid); + if (ret) + dev_warn(ghvm->parent, + "Failed to deallocate vmid: %d\n", ret); + } gunyah_rm_put(ghvm->rm); kfree(ghvm); @@ -40,6 +236,8 @@ static int gunyah_vm_release(struct inode *inode, struct file *filp) static const struct file_operations gunyah_vm_fops = { .owner = THIS_MODULE, + .unlocked_ioctl = gunyah_vm_ioctl, + .compat_ioctl = compat_ptr_ioctl, .release = gunyah_vm_release, .llseek = noop_llseek, }; diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index 50790d4026765..e6cc9aead0b67 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -7,6 +7,8 @@ #define _GUNYAH_VM_MGR_PRIV_H #include +#include +#include #include @@ -17,12 +19,29 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, /** * struct gunyah_vm - Main representation of a Gunyah Virtual machine + * @vmid: Gunyah's VMID for this virtual machine * @rm: Pointer to the resource manager struct to make RM calls * @parent: For logging + * @nb: Notifier block for RM notifications + * @vm_status: Current state of the VM, as last reported by RM + * @vm_status_wait: Wait queue for status @vm_status changes + * @status_lock: Serializing state transitions + * @auth: Authentication mechanism to be used by resource manager when + * launching the VM + * + * Members are grouped by hot path. */ struct gunyah_vm { + u16 vmid; struct gunyah_rm *rm; + + struct notifier_block nb; + enum gunyah_rm_vm_status vm_status; + wait_queue_head_t vm_status_wait; + struct rw_semaphore status_lock; + struct device *parent; + enum gunyah_rm_vm_auth_mechanism auth; }; #endif diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index ac338ec4b85dd..31e7f79a6c398 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -20,4 +20,9 @@ */ #define GUNYAH_CREATE_VM _IO(GUNYAH_IOCTL_TYPE, 0x0) /* Returns a Gunyah VM fd */ +/* + * ioctls for gunyah-vm fds (returned by GUNYAH_CREATE_VM) + */ +#define GUNYAH_VM_START _IO(GUNYAH_IOCTL_TYPE, 0x3) + #endif From patchwork Thu Feb 22 23:16:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE8D9C54798 for ; Thu, 22 Feb 2024 23:17:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 142386B008A; Thu, 22 Feb 2024 18:16:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CAF66B008C; Thu, 22 Feb 2024 18:16:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A19DD6B008A; Thu, 22 Feb 2024 18:16:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5AEB46B008A for ; Thu, 22 Feb 2024 18:16:45 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A94D0140F56 for ; Thu, 22 Feb 2024 23:16:44 +0000 (UTC) X-FDA: 81821001528.02.3A47623 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf06.hostedemail.com (Postfix) with ESMTP id 8C7FF18001B for ; Thu, 22 Feb 2024 23:16:42 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=m667LTrq; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf06.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643802; a=rsa-sha256; cv=none; b=VsONHJnb1TG+4Lbvj/SCOwIZjF/p1uLV9Kap/8gfwycgd7skTwehUniBdtffAqlC2jN/Ao uKt8Yf3yeZUZMjwkIde/VfpZkuUnWhQOZ8TPoTPIjXk1uMJmQ6AxTmJHpdWXU5eo/4WoB4 HayhLRKTx7SM0oRsBIk/ROiJfPtaUD8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=m667LTrq; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf06.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643802; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RFrpvK2ncCEA3pXuIWUNixiWOQ+1QGG1zWVmRqVDqG8=; b=JEVSmsYF0yqhK22/geuXpKu6s/KT98DUNN4e2wbolBClq4nSXqNwL3TcJkkc0jGFS6mqvT RF+LRQg3RAAjUSHxzRPoamRCMEmat6ekwHHublmMeiymWeUW3qs4a12HybdShC54vrxu/x Rlm9JFZz6hb43tHL6dBH0C6D1KBraco= Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMT6YA003866; Thu, 22 Feb 2024 23:16:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=RFrpvK2ncCEA3pXuIWUNixiWOQ+1QGG1zWVmRqVDqG8 =; b=m667LTrq+pQJLoeLwUiFbZ0WPVvbpUz5ZSQJDDs4ROMQCrDYiIXVFCZyxki cVaDNfVvESh1i9Zspzzi616cDjC7uJFMM7/ODi708TpmEPNFUn8BMPZ091pfYeQZ 29gIVYlJ9JGklhmafgN7G+x0SdMWWfbsI2TpBkenD32XIlta06RMgNn3cdFyNQUO ZOFoRx5O8ShU/ftSzzSwyU203n9y3oYGMIqJNuhH31ZY8L2A7ikNicrRTMoPMnIl aILlKE8i0Y2dZtlz2ruBErITN9jX7A+jNAeYuLNFWfBMGVwaElRqjZUVpmr3BCeV T8IYqbA7A2AULng+NtaJ7/T7yyw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wdvwwbj6w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:34 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGXdK015985 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:33 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:32 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:34 -0800 Subject: [PATCH v17 11/35] virt: gunyah: Translate gh_rm_hyp_resource into gunyah_resource MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-11-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: qeUnMGLImSCMNFcN-vw0JZKmgk1Qogf9 X-Proofpoint-GUID: qeUnMGLImSCMNFcN-vw0JZKmgk1Qogf9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 spamscore=0 impostorscore=0 mlxlogscore=952 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8C7FF18001B X-Stat-Signature: yb5f4oqw4mnt3pzzmfpasa94od66wt6k X-HE-Tag: 1708643802-622100 X-HE-Meta: U2FsdGVkX1/4sygpI+yylCcNZkpxV86aonsTcmnGbpv4e7K05xWMqRDGO1HLOlnoKGiwm/uojYHGEjyud4AdGbdGE/g+nTtPXwYVMmPKJijg3z0CMqxhniJYmYqt6qTp5/WUCUwhuXCEmB5AEL2vSfxQl8OpXTTUkhuu61Hc2gImJ2t7tpYs/qjpUBZqdatZN9seeAFsGT36RWVFBtLmLc2sp4nxRNyj1ph/ZU+v0tfSh5RdG4XN//CgFUYeRvK5sIBmLXHoENxH+UwYc4ddYHs1LCHBjJ1ZlcUdkAG5/nyWLrg1CEqGmeJLuLkYz+Zqo9mWarE0vwDxxRmU13bC3b4Wqo0JWA+MRLH21madoQiMtlqYigho87ZlmKZqE43PLTEXQYHk/1oaNYiX7HaxZvPTOQEPSRHkDu/t1I06CkF9Uwo6NpwPJyRE1qJXxC/qqwZCdwgu+tTNdJFYJeuD4BxGf45cl/vF+oqoTW+cecGCJqB5XYAYUAYplI6NLqf2rW43w/HkT+nnqEzA38eW/TeG5weLg43pL0RWgPo8fakqTJlSth0o1jCNivn3QlRtA3uB0hn0mnLcSben1vuVv22FkveWSvdCz9A72rP22Cv90OEtmHla/wgHYChnPrsIjKgY/3wfAi3qz9v5eWn7ZWUD3iZ4S7gjjENQBHrTRPcMQkVK5TYkiN7UE14LxAa6fBZPziwTDEt0xajmfu9Af+dLmsp6KQMyazwGqW0y/ICP3KOb7m9YtEmJ8Jvr9ltuqhC1fEWWtrg/rScnmXRSQPppW2jtX+rijH43nDiAONcyTjeB7TO5ZgWSgxbZJyhxDC93ftVwIyQx0LgOQT8sJSI70poV2QPiXmStQ3J5g3hQJmDattITcRMcxxaOn5PVhF2rwRfwvAAuqpStnUAb/lO+ymZBDxS5xLMlPbTuNocDqnVlKcReIanIE5Ro+Tuef3jtYZAQn3qjt9hv9Yr 5rE0BAKT Tapf+epNTG39nzc26ykbSeUEcmPHQKUFn3cG3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When booting a Gunyah virtual machine, the host VM may gain capabilities to interact with resources for the guest virtual machine. Examples of such resources are vCPUs or message queues. To use those resources, we need to translate the RM response into a gunyah_resource structure which are useful to Linux drivers. Presently, Linux drivers need only to know the type of resource, the capability ID, and an interrupt. On ARM64 systems, the interrupt reported by Gunyah is the GIC interrupt ID number and always a SPI or extended SPI. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- arch/arm64/include/asm/gunyah.h | 36 ++++++++++++++++++++++ drivers/virt/gunyah/rsc_mgr.c | 67 +++++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/rsc_mgr.h | 5 +++ include/linux/gunyah.h | 2 ++ 4 files changed, 110 insertions(+) diff --git a/arch/arm64/include/asm/gunyah.h b/arch/arm64/include/asm/gunyah.h new file mode 100644 index 0000000000000..0cd3debe22b64 --- /dev/null +++ b/arch/arm64/include/asm/gunyah.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#ifndef _ASM_GUNYAH_H +#define _ASM_GUNYAH_H + +#include +#include + +static inline int arch_gunyah_fill_irq_fwspec_params(u32 virq, + struct irq_fwspec *fwspec) +{ + /* Assume that Gunyah gave us an SPI or ESPI; defensively check it */ + if (WARN(virq < 32, "Unexpected virq: %d\n", virq)) { + return -EINVAL; + } else if (virq <= 1019) { + fwspec->param_count = 3; + fwspec->param[0] = 0; /* GIC_SPI */ + fwspec->param[1] = virq - 32; /* virq 32 -> SPI 0 */ + fwspec->param[2] = IRQ_TYPE_EDGE_RISING; + } else if (WARN(virq < 4096, "Unexpected virq: %d\n", virq)) { + return -EINVAL; + } else if (virq < 5120) { + fwspec->param_count = 3; + fwspec->param[0] = 2; /* GIC_ESPI */ + fwspec->param[1] = virq - 4096; /* virq 4096 -> ESPI 0 */ + fwspec->param[2] = IRQ_TYPE_EDGE_RISING; + } else { + WARN(1, "Unexpected virq: %d\n", virq); + return -EINVAL; + } + return 0; +} + +#endif diff --git a/drivers/virt/gunyah/rsc_mgr.c b/drivers/virt/gunyah/rsc_mgr.c index fb0efe68f0e22..c320c9ceaf8ac 100644 --- a/drivers/virt/gunyah/rsc_mgr.c +++ b/drivers/virt/gunyah/rsc_mgr.c @@ -9,9 +9,12 @@ #include #include #include +#include #include #include +#include + #include "rsc_mgr.h" #include "vm_mgr.h" @@ -121,6 +124,7 @@ struct gunyah_rm_message { * @send_ready: completed when we know Tx message queue can take more messages * @nh: notifier chain for clients interested in RM notification messages * @miscdev: /dev/gunyah + * @parent_fwnode: Parent IRQ fwnode to translate Gunyah hwirqs to Linux irqs */ struct gunyah_rm { struct device *dev; @@ -138,6 +142,7 @@ struct gunyah_rm { struct blocking_notifier_head nh; struct miscdevice miscdev; + struct fwnode_handle *parent_fwnode; }; /** @@ -178,6 +183,53 @@ static inline int gunyah_rm_error_remap(enum gunyah_rm_error rm_error) } } +struct gunyah_resource * +gunyah_rm_alloc_resource(struct gunyah_rm *rm, + struct gunyah_rm_hyp_resource *hyp_resource) +{ + struct gunyah_resource *ghrsc; + int ret; + + ghrsc = kzalloc(sizeof(*ghrsc), GFP_KERNEL); + if (!ghrsc) + return NULL; + + ghrsc->type = hyp_resource->type; + ghrsc->capid = le64_to_cpu(hyp_resource->cap_id); + ghrsc->irq = IRQ_NOTCONNECTED; + ghrsc->rm_label = le32_to_cpu(hyp_resource->resource_label); + if (hyp_resource->virq) { + struct irq_fwspec fwspec; + + + fwspec.fwnode = rm->parent_fwnode; + ret = arch_gunyah_fill_irq_fwspec_params(le32_to_cpu(hyp_resource->virq), &fwspec); + if (ret) { + dev_err(rm->dev, + "Failed to translate interrupt for resource %d label: %d: %d\n", + ghrsc->type, ghrsc->rm_label, ret); + } + + ret = irq_create_fwspec_mapping(&fwspec); + if (ret < 0) { + dev_err(rm->dev, + "Failed to allocate interrupt for resource %d label: %d: %d\n", + ghrsc->type, ghrsc->rm_label, ret); + kfree(ghrsc); + return NULL; + } + ghrsc->irq = ret; + } + + return ghrsc; +} + +void gunyah_rm_free_resource(struct gunyah_resource *ghrsc) +{ + irq_dispose_mapping(ghrsc->irq); + kfree(ghrsc); +} + static int gunyah_rm_init_message_payload(struct gunyah_rm_message *message, const void *msg, size_t hdr_size, size_t msg_size) @@ -707,6 +759,7 @@ static int gunyah_rm_probe_rx_msgq(struct gunyah_rm *rm, static int gunyah_rm_probe(struct platform_device *pdev) { + struct device_node *parent_irq_node; struct gunyah_rm *rm; int ret; @@ -734,6 +787,20 @@ static int gunyah_rm_probe(struct platform_device *pdev) if (ret) return ret; + parent_irq_node = of_irq_find_parent(pdev->dev.of_node); + if (!parent_irq_node) { + dev_err(&pdev->dev, + "Failed to find interrupt parent of resource manager\n"); + return -ENODEV; + } + + rm->parent_fwnode = of_node_to_fwnode(parent_irq_node); + if (!rm->parent_fwnode) { + dev_err(&pdev->dev, + "Failed to find interrupt parent domain of resource manager\n"); + return -ENODEV; + } + rm->miscdev.parent = &pdev->dev; rm->miscdev.name = "gunyah"; rm->miscdev.minor = MISC_DYNAMIC_MINOR; diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index 205b9ea735e53..52711de77bb79 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -99,6 +99,11 @@ struct gunyah_rm_hyp_resources { int gunyah_rm_get_hyp_resources(struct gunyah_rm *rm, u16 vmid, struct gunyah_rm_hyp_resources **resources); +struct gunyah_resource * +gunyah_rm_alloc_resource(struct gunyah_rm *rm, + struct gunyah_rm_hyp_resource *hyp_resource); +void gunyah_rm_free_resource(struct gunyah_resource *ghrsc); + int gunyah_rm_call(struct gunyah_rm *rsc_mgr, u32 message_id, const void *req_buf, size_t req_buf_size, void **resp_buf, size_t *resp_buf_size); diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index acd70f9824253..45033bdb5e151 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -29,6 +29,8 @@ struct gunyah_resource { enum gunyah_resource_type type; u64 capid; unsigned int irq; + + u32 rm_label; }; /******************************************************************************/ From patchwork Thu Feb 22 23:16:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EE7DC47DD9 for ; Thu, 22 Feb 2024 23:17:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1EF96B0092; Thu, 22 Feb 2024 18:16:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A5F66B0096; Thu, 22 Feb 2024 18:16:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 731D56B0095; Thu, 22 Feb 2024 18:16:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5C03F6B0092 for ; Thu, 22 Feb 2024 18:16:45 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B3F2F810AB for ; Thu, 22 Feb 2024 23:16:44 +0000 (UTC) X-FDA: 81821001528.01.89D9C30 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf20.hostedemail.com (Postfix) with ESMTP id AAA7F1C0013 for ; Thu, 22 Feb 2024 23:16:42 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=otq4Ebhn; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf20.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643802; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EUBUNUzBwIcURuOIlm3h185kp8+2tYCThOEXOOt52VA=; b=TDnvLf9bSvo0/C2V3SqF9O/Yxj15N7OSx6ge9r2JFBzaVUL7hn3HocYk+se0S9t4Ea2MNP Ed3pgX9b2dPNCjYlsdwp+uJGMaWRyZg0oNUsCZUmFldvDfEejpoblmSSn+ub2XbtvXTycr UDoXHePSCX5b1ppxxEronuvZc5OAszU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=otq4Ebhn; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf20.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643802; a=rsa-sha256; cv=none; b=xdR3qYxYXZVPpcmYouF4EMoB9WWcJw+OX3LDeEcE/x/clMqPUC4NT0pyoBapQ05zGhrE2F SRMapFzDeJ9guJpuDdD+qdtzVbF7yaud9X3A0EAx0JzucBXOcUsGsPMdki5S0BjIMadY0k 80c4Mob5xl/vpmPF4BAiyUpfR2j3aX8= Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMB4nv021355; Thu, 22 Feb 2024 23:16:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=EUBUNUzBwIcURuOIlm3h185kp8+2tYCThOEXOOt52VA =; b=otq4EbhnoRE7B1cjgZcXmLB5YZWJVFS9GKpDx6c8u0pJWDFskH+OJratmB0 6lDIJknYnm1LmnSw+EC9tzCz/XeIm/gP6lIRseICDUNzQKG8HbOF9HIGASLwEMs2 RP7XJ1s5/G2uPP77t7Ys2B+9ADdQKPVwscY9iDIvLtJxQ6sZ9AlXxYZOhlPGNPDZ BoiU2RhiqUSj2VrZa6MZkoSv9uCUFEnOVDHNOPj6xsVnVp3Sc4WbK4zZV0KV7WDR 5QgqnEhoFMLD2CgU4B/T6i15go8U+XMSNphPWbTNBDOcK9nBELUDhjpWgrnX+ueC IoT/5P0hwRiIB95kFIr4ikXSTLQ== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we24ajumb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:34 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGYrl018220 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:34 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:33 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:35 -0800 Subject: [PATCH v17 12/35] virt: gunyah: Add resource tickets MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-12-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: zz6oR4icIHFIvRsilpR2bBxQjadrGrxK X-Proofpoint-ORIG-GUID: zz6oR4icIHFIvRsilpR2bBxQjadrGrxK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 adultscore=0 mlxlogscore=999 phishscore=0 spamscore=0 mlxscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: AAA7F1C0013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: iz7dh46s8bd6awwpqw54ibum4wqummwh X-HE-Tag: 1708643802-904966 X-HE-Meta: U2FsdGVkX198cReMhARRW14Fm8TeFqAnNXd8I2/d0iMe3fljrzVU+P9luCnOIQPY9VyHR4Fl9GruFyevP9tICQQbPtGvZY/z/9i95Qq86r4nxdTh84o73sLDiWu9HpTDPadfyJDZTA0+tq/IXSIyLhMuaFwVC5mJiGBH+dEuCRIByvXjC4nmsI/8HywV+4ZG4kyezhjZKYcvlfMlToOBJ/56ertX14MiejPIEKCc+3j/Qv16IJeGXT5CNY+GGIO3oXohYSk42e2Xn4SgH8gfw4KGYpTShRbpwoT4WnNbGWaP6tCSEAQ58e1KWfHLvokHpB141PQiqz9t6PRJuV/s6DyXafTz+fdQZM/s8NEBThFjgSUGsIxJrcaA1rPor4U1oGngdPpPe2zIVV2mRRTwISxKRG3CIxjVlAv/LJOxIyHllmMWeT0Dboi6rU5Oxw9/XzkMqNAUCyN/THSOK/Ksoh1k8tyczS6t6ByTFh7POsOI9jQz3EVrhcNtYrG/K5TAocjlgSr/jt1qi/rrqqeWzgwUk9DMsjd8kNQYN1TTQhzjzx6EXkSM8LoUoAz40oKAorMEBnpu6sIH9TCWHULLQy8+w8UTFsjoH7Egbbn7dmZ/Nk2rYjiv18LKTJA0s+LAlkRSnOMg7Ux97Nr4PnL+Tgdea8WgVeiixAiQHOycaZp5qd7iQm0BKU8oBPal+BgNrBNZcyiaE2nBfu4xMI/yWIl+FW3dEtEONLuwwREtUcmAApiJqRxd+RnU3EbqXo2QCdRA/2jYkAKSPcYWDWBJLbjOfYhwcIFiJTd1tM29Sd60EZ1nX7umex+ILdoZym0lrxLRrtkSfu/X68qdFQnv43ApfiCGqN5ovR/HxLqEFYGxNY7hRWYwJITfUTX7Y1ZNeSWFpwg77aGc3GW3U1mYBcuEjwgvuH7ki8OEbG/R/ePUmK4q/K5677iuv2GuclEer9V4nK2Oshk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Some VM functions need to acquire Gunyah resources. For instance, Gunyah vCPUs are exposed to the host as a resource. The Gunyah vCPU function will register a resource ticket and be able to interact with the hypervisor once the resource ticket is filled. Resource tickets are the mechanism for functions to acquire ownership of Gunyah resources. Gunyah functions can be created before the VM's resources are created and made available to Linux. A resource ticket identifies a type of resource and a label of a resource which the ticket holder is interested in. Resources are created by Gunyah as configured in the VM's devicetree configuration. Gunyah doesn't process the label and that makes it possible for userspace to create multiple resources with the same label. Resource ticket owners need to be prepared for populate to be called multiple times if userspace created multiple resources with the same label. Reviewed-by: Alex Elder Signed-off-by: Elliot Berman --- drivers/virt/gunyah/vm_mgr.c | 135 ++++++++++++++++++++++++++++++++++++++++++- drivers/virt/gunyah/vm_mgr.h | 7 +++ include/linux/gunyah.h | 40 +++++++++++++ 3 files changed, 181 insertions(+), 1 deletion(-) diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index 364a53cad643e..2cde4d501204a 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -15,6 +15,113 @@ #include "rsc_mgr.h" #include "vm_mgr.h" +int gunyah_vm_add_resource_ticket(struct gunyah_vm *ghvm, + struct gunyah_vm_resource_ticket *ticket) +{ + struct gunyah_vm_resource_ticket *iter; + struct gunyah_resource *ghrsc, *rsc_iter; + int ret = 0; + + mutex_lock(&ghvm->resources_lock); + list_for_each_entry(iter, &ghvm->resource_tickets, vm_list) { + if (iter->resource_type == ticket->resource_type && + iter->label == ticket->label) { + ret = -EEXIST; + goto out; + } + } + + if (!try_module_get(ticket->owner)) { + ret = -ENODEV; + goto out; + } + + list_add(&ticket->vm_list, &ghvm->resource_tickets); + INIT_LIST_HEAD(&ticket->resources); + + list_for_each_entry_safe(ghrsc, rsc_iter, &ghvm->resources, list) { + if (ghrsc->type == ticket->resource_type && + ghrsc->rm_label == ticket->label) { + if (ticket->populate(ticket, ghrsc)) + list_move(&ghrsc->list, &ticket->resources); + } + } +out: + mutex_unlock(&ghvm->resources_lock); + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_vm_add_resource_ticket); + +static void +__gunyah_vm_remove_resource_ticket(struct gunyah_vm *ghvm, + struct gunyah_vm_resource_ticket *ticket) +{ + struct gunyah_resource *ghrsc, *iter; + + list_for_each_entry_safe(ghrsc, iter, &ticket->resources, list) { + ticket->unpopulate(ticket, ghrsc); + list_move(&ghrsc->list, &ghvm->resources); + } + + module_put(ticket->owner); + list_del(&ticket->vm_list); +} + +void gunyah_vm_remove_resource_ticket(struct gunyah_vm *ghvm, + struct gunyah_vm_resource_ticket *ticket) +{ + mutex_lock(&ghvm->resources_lock); + __gunyah_vm_remove_resource_ticket(ghvm, ticket); + mutex_unlock(&ghvm->resources_lock); +} +EXPORT_SYMBOL_GPL(gunyah_vm_remove_resource_ticket); + +static void gunyah_vm_add_resource(struct gunyah_vm *ghvm, + struct gunyah_resource *ghrsc) +{ + struct gunyah_vm_resource_ticket *ticket; + + mutex_lock(&ghvm->resources_lock); + list_for_each_entry(ticket, &ghvm->resource_tickets, vm_list) { + if (ghrsc->type == ticket->resource_type && + ghrsc->rm_label == ticket->label) { + if (ticket->populate(ticket, ghrsc)) + list_add(&ghrsc->list, &ticket->resources); + else + list_add(&ghrsc->list, &ghvm->resources); + /* unconditonal -- we prevent multiple identical + * resource tickets so there will not be some other + * ticket elsewhere in the list if populate() failed. + */ + goto found; + } + } + list_add(&ghrsc->list, &ghvm->resources); +found: + mutex_unlock(&ghvm->resources_lock); +} + +static void gunyah_vm_clean_resources(struct gunyah_vm *ghvm) +{ + struct gunyah_vm_resource_ticket *ticket, *titer; + struct gunyah_resource *ghrsc, *riter; + + mutex_lock(&ghvm->resources_lock); + if (!list_empty(&ghvm->resource_tickets)) { + dev_warn(ghvm->parent, "Dangling resource tickets:\n"); + list_for_each_entry_safe(ticket, titer, &ghvm->resource_tickets, + vm_list) { + dev_warn(ghvm->parent, " %pS\n", ticket->populate); + __gunyah_vm_remove_resource_ticket(ghvm, ticket); + } + } + + list_for_each_entry_safe(ghrsc, riter, &ghvm->resources, list) { + gunyah_rm_free_resource(ghrsc); + } + mutex_unlock(&ghvm->resources_lock); +} + static int gunyah_vm_rm_notification_status(struct gunyah_vm *ghvm, void *data) { struct gunyah_rm_vm_status_payload *payload = data; @@ -92,13 +199,18 @@ static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) init_rwsem(&ghvm->status_lock); init_waitqueue_head(&ghvm->vm_status_wait); ghvm->vm_status = GUNYAH_RM_VM_STATUS_NO_STATE; + mutex_init(&ghvm->resources_lock); + INIT_LIST_HEAD(&ghvm->resources); + INIT_LIST_HEAD(&ghvm->resource_tickets); return ghvm; } static int gunyah_vm_start(struct gunyah_vm *ghvm) { - int ret; + struct gunyah_rm_hyp_resources *resources; + struct gunyah_resource *ghrsc; + int ret, i, n; down_write(&ghvm->status_lock); if (ghvm->vm_status != GUNYAH_RM_VM_STATUS_NO_STATE) { @@ -134,6 +246,25 @@ static int gunyah_vm_start(struct gunyah_vm *ghvm) } ghvm->vm_status = GUNYAH_RM_VM_STATUS_READY; + ret = gunyah_rm_get_hyp_resources(ghvm->rm, ghvm->vmid, &resources); + if (ret) { + dev_warn(ghvm->parent, + "Failed to get hypervisor resources for VM: %d\n", + ret); + goto err; + } + + for (i = 0, n = le32_to_cpu(resources->n_entries); i < n; i++) { + ghrsc = gunyah_rm_alloc_resource(ghvm->rm, + &resources->entries[i]); + if (!ghrsc) { + ret = -ENOMEM; + goto err; + } + + gunyah_vm_add_resource(ghvm, ghrsc); + } + ret = gunyah_rm_vm_start(ghvm->rm, ghvm->vmid); if (ret) { dev_warn(ghvm->parent, "Failed to start VM: %d\n", ret); @@ -207,6 +338,8 @@ static int gunyah_vm_release(struct inode *inode, struct file *filp) if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_RUNNING) gunyah_vm_stop(ghvm); + gunyah_vm_clean_resources(ghvm); + if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_EXITED || ghvm->vm_status == GUNYAH_RM_VM_STATUS_READY || ghvm->vm_status == GUNYAH_RM_VM_STATUS_INIT_FAILED) { diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index e6cc9aead0b67..0d291f7228859 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -26,6 +26,9 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, * @vm_status: Current state of the VM, as last reported by RM * @vm_status_wait: Wait queue for status @vm_status changes * @status_lock: Serializing state transitions + * @resource_lock: Serializing addition of resources and resource tickets + * @resources: List of &struct gunyah_resource that are associated with this VM + * @resource_tickets: List of &struct gunyah_vm_resource_ticket * @auth: Authentication mechanism to be used by resource manager when * launching the VM * @@ -39,9 +42,13 @@ struct gunyah_vm { enum gunyah_rm_vm_status vm_status; wait_queue_head_t vm_status_wait; struct rw_semaphore status_lock; + struct mutex resources_lock; + struct list_head resources; + struct list_head resource_tickets; struct device *parent; enum gunyah_rm_vm_auth_mechanism auth; + }; #endif diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 45033bdb5e151..0017691002607 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -10,6 +10,7 @@ #include #include #include +#include #include /* Matches resource manager's resource types for VM_GET_HYP_RESOURCES RPC */ @@ -30,9 +31,48 @@ struct gunyah_resource { u64 capid; unsigned int irq; + struct list_head list; u32 rm_label; }; +struct gunyah_vm; + +/** + * struct gunyah_vm_resource_ticket - Represents a ticket to reserve access to VM resource(s) + * @vm_list: for @gunyah_vm->resource_tickets + * @resources: List of resource(s) associated with this ticket + * (members are from @gunyah_resource->list) + * @resource_type: Type of resource this ticket reserves + * @label: Label of the resource from resource manager this ticket reserves. + * @owner: owner of the ticket + * @populate: callback provided by the ticket owner and called when a resource is found that + * matches @resource_type and @label. Note that this callback could be called + * multiple times if userspace created mutliple resources with the same type/label. + * This callback may also have significant delay after gunyah_vm_add_resource_ticket() + * since gunyah_vm_add_resource_ticket() could be called before the VM starts. + * @unpopulate: callback provided by the ticket owner and called when the ticket owner should no + * longer use the resource provided in the argument. When unpopulate() returns, + * the ticket owner should not be able to use the resource any more as the resource + * might being freed. + */ +struct gunyah_vm_resource_ticket { + struct list_head vm_list; + struct list_head resources; + enum gunyah_resource_type resource_type; + u32 label; + + struct module *owner; + bool (*populate)(struct gunyah_vm_resource_ticket *ticket, + struct gunyah_resource *ghrsc); + void (*unpopulate)(struct gunyah_vm_resource_ticket *ticket, + struct gunyah_resource *ghrsc); +}; + +int gunyah_vm_add_resource_ticket(struct gunyah_vm *ghvm, + struct gunyah_vm_resource_ticket *ticket); +void gunyah_vm_remove_resource_ticket(struct gunyah_vm *ghvm, + struct gunyah_vm_resource_ticket *ticket); + /******************************************************************************/ /* Common arch-independent definitions for Gunyah hypercalls */ #define GUNYAH_CAPID_INVAL U64_MAX From patchwork Thu Feb 22 23:16:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F652C47DD9 for ; Thu, 22 Feb 2024 23:17:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 516936B0096; Thu, 22 Feb 2024 18:16:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 499CA6B0098; Thu, 22 Feb 2024 18:16:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 252986B0099; Thu, 22 Feb 2024 18:16:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0B2776B0096 for ; Thu, 22 Feb 2024 18:16:47 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DBE7EA0AAD for ; Thu, 22 Feb 2024 23:16:46 +0000 (UTC) X-FDA: 81821001612.15.A82A164 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf20.hostedemail.com (Postfix) with ESMTP id D0F401C000D for ; Thu, 22 Feb 2024 23:16:44 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=ZYa5PvTE; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf20.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643804; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hjkuOMml2lLPxrsAbD1E2lRJVtx0etVrUgoraJTr6dw=; b=Fi7EVPSKVVWD5msshgBhG5epbdQ/8bBWuz/j4wQUD5o1wAxa29lbmegJjwuikt3DorTZ/J 8TcJda+W+yY9xjAv1NmtqD2Pbk7PeJYTG9o1vX5Xt7XQ5WFue8FCaT/gctj1VwEho2IYVD DRCMI7k3Qr8chDvFtATPz9BwlfBWO+U= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=ZYa5PvTE; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf20.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643804; a=rsa-sha256; cv=none; b=qXIrB9OjSQpmYfK/v4OJ0TayEfU4/Hm7lkWsbRczhJ0xs8tVXESscURrQ/cEEPlrfB1/te FoMQ3pZ4+NgdVFy9GSm6FqjheDunx+GXvCmdRRqL0rioKZ2+yxcLZNUkxSd85jJ0lu2yqL qkZFPD44T4EB7P0+TeViCyxggEv2vPI= Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLRZBE019938; Thu, 22 Feb 2024 23:16:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=hjkuOMml2lLPxrsAbD1E2lRJVtx0etVrUgoraJTr6dw =; b=ZYa5PvTEjk/l4HzHk7E2mk3n7dwMldK1ZBClQiCLQha8iKxY/fy1X7EgERN rLrNbC0Fax8GD4vjgZzgb2Hg/z1DWrdDyodhHekM24xpG3O2U96N8tdtfAa015qf W+GyyWur7Z8/CyMnTYUD+9XMULOgkxvgWAZWOoM757//wat/3zZQvJiaYMwx7Kl8 NCQCAVlvfHBN+SqrRymFZrC+NTwQ89eTHqH7RRd6cDlRd6s1n560Dldfmfw4W0X5 WmUka47BVpaohG0XLu7+Z8Nn904IYwoRpsvucrqYlF9sg+plKEgk0oEKfDHgyJIN SkMi4cewIEmRIDUW5Fy26zvjjmg== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we97tgf8b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:35 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGYdX017469 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:34 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:34 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:36 -0800 Subject: [PATCH v17 13/35] gunyah: vm_mgr: Add framework for VM Functions MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-13-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: G4o5lshGena-Ci4TAmTqxq_ZScpiMa0Z X-Proofpoint-ORIG-GUID: G4o5lshGena-Ci4TAmTqxq_ZScpiMa0Z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 adultscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D0F401C000D X-Stat-Signature: hrmqdosaioaa1ga5hktwc641g7srnqks X-Rspam-User: X-HE-Tag: 1708643804-783988 X-HE-Meta: U2FsdGVkX1+eV3Y29/Cdo1e0c0CHSzJafCcuKbEYz6V28HS1bOZag1djgK0X2qeGBhxHk8UgeMjltMP6n+ZvLYtXrRWr5hFCjFm2RlxC7HTG/aUI+Oj41F6FR9eIPknUFB2A9ZwEDSyCqRoYreAM0WQNR6DzMPxkgMNIHxJMu4JKYJxKvbetmUCRdMy2HhJllebnjO1WO45bKK9ftK60SvzY0FN3zwhE2Ij3+elaLiHkqCqgXwJBvrGCpJ2y9+mAEPnmJzr6nzgzowBF5h85TZ28kloeW5d6cuydBWcnqHB5L1oJcw/UWGjE3/s0Fn0Qw7P1+S8w3i40wy/52cL/OprpJ+ZznRS5gi71k6p1PFqqlfXmlAA1/VT/TcMiQY8jVyULyi66ZEv+XA5ODcqHGq4TD+741R3q0ji3Q+yvoSiRQSnO8ddhUL7nm2qFfKp2OHb4H2IiI/KV34S2BQAjuRaRsLtBlG9XcINUgjzKpSDSv/bSW7tzE/0lET3ZIuqLAQz/gac66btlqG2dJYdvyxV+sQ4uPoGqxS6R/H8IeLVCDfPfvNOF21Du0zSh4F5pEj341zY7G8I7ZUuehkZtiRmfxXcll2oHSl/tXntiI8QvC5yaY9wcpNqkjRfy1Uy7Q4eEyl+b55wqpfKuzsoiOXt9mMau3Ye0DWG6JKCiMLWO4IsVS+tIMYp83jy7JlvsZStIqBhkf7hJUX05ZgSf0e/ugr9mCZ/BtAa0oJykW/kxBE/DosRPX2lc4NMwFxm+yDdyMekqhFD+mgkT6XHhiDsfPX5IJMJSTO4c0u24c6HjUrvfDf35+UosB0rnnevp2TdHGL9rAlJiprLA2rGSQTInkPRzL2d0u3yGrCtwH2SB6YlX59qA4wv/xD7rPclrK+UPjekCCo+vDPS3sv9iXkvdqlblUcu0KVg6qo8ustFT56vh+4YGud4FdeBtk8uEwZmPej+pfyJ6cwlAPEq F0JcjSM/ MAmdCDy4TEqVoD89HNkrkmGUwH6uWADyCjXoO X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Introduce a framework for Gunyah userspace to install VM functions. VM functions are optional interfaces to the virtual machine. vCPUs, ioeventfs, and irqfds are examples of such VM functions and are implemented in subsequent patches. A generic framework is implemented instead of individual ioctls to create vCPUs, irqfds, etc., in order to simplify the VM manager core implementation and allow dynamic loading of VM function modules. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- drivers/virt/gunyah/vm_mgr.c | 207 ++++++++++++++++++++++++++++++++++++++++++- drivers/virt/gunyah/vm_mgr.h | 10 +++ include/linux/gunyah.h | 86 +++++++++++++++++- include/uapi/linux/gunyah.h | 18 ++++ 4 files changed, 317 insertions(+), 4 deletions(-) diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index 2cde4d501204a..a619dd10972a5 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -6,15 +6,175 @@ #define pr_fmt(fmt) "gunyah_vm_mgr: " fmt #include +#include #include #include #include +#include #include #include "rsc_mgr.h" #include "vm_mgr.h" +static DEFINE_XARRAY(gunyah_vm_functions); + +static void gunyah_vm_put_function(struct gunyah_vm_function *fn) +{ + module_put(fn->mod); +} + +static struct gunyah_vm_function *gunyah_vm_get_function(u32 type) +{ + struct gunyah_vm_function *fn; + + fn = xa_load(&gunyah_vm_functions, type); + if (!fn) { + request_module("ghfunc:%d", type); + + fn = xa_load(&gunyah_vm_functions, type); + } + + if (!fn || !try_module_get(fn->mod)) + fn = ERR_PTR(-ENOENT); + + return fn; +} + +static void +gunyah_vm_remove_function_instance(struct gunyah_vm_function_instance *inst) + __must_hold(&inst->ghvm->fn_lock) +{ + inst->fn->unbind(inst); + list_del(&inst->vm_list); + gunyah_vm_put_function(inst->fn); + kfree(inst->argp); + kfree(inst); +} + +static void gunyah_vm_remove_functions(struct gunyah_vm *ghvm) +{ + struct gunyah_vm_function_instance *inst, *iiter; + + mutex_lock(&ghvm->fn_lock); + list_for_each_entry_safe(inst, iiter, &ghvm->functions, vm_list) { + gunyah_vm_remove_function_instance(inst); + } + mutex_unlock(&ghvm->fn_lock); +} + +static long gunyah_vm_add_function_instance(struct gunyah_vm *ghvm, + struct gunyah_fn_desc *f) +{ + struct gunyah_vm_function_instance *inst; + void __user *argp; + long r = 0; + + if (f->arg_size > GUNYAH_FN_MAX_ARG_SIZE) { + dev_err_ratelimited(ghvm->parent, "%s: arg_size > %d\n", + __func__, GUNYAH_FN_MAX_ARG_SIZE); + return -EINVAL; + } + + inst = kzalloc(sizeof(*inst), GFP_KERNEL); + if (!inst) + return -ENOMEM; + + inst->arg_size = f->arg_size; + if (inst->arg_size) { + inst->argp = kzalloc(inst->arg_size, GFP_KERNEL); + if (!inst->argp) { + r = -ENOMEM; + goto free; + } + + argp = u64_to_user_ptr(f->arg); + if (copy_from_user(inst->argp, argp, f->arg_size)) { + r = -EFAULT; + goto free_arg; + } + } + + inst->fn = gunyah_vm_get_function(f->type); + if (IS_ERR(inst->fn)) { + r = PTR_ERR(inst->fn); + goto free_arg; + } + + inst->ghvm = ghvm; + inst->rm = ghvm->rm; + + mutex_lock(&ghvm->fn_lock); + r = inst->fn->bind(inst); + if (r < 0) { + mutex_unlock(&ghvm->fn_lock); + gunyah_vm_put_function(inst->fn); + goto free_arg; + } + + list_add(&inst->vm_list, &ghvm->functions); + mutex_unlock(&ghvm->fn_lock); + + return r; +free_arg: + kfree(inst->argp); +free: + kfree(inst); + return r; +} + +static long gunyah_vm_rm_function_instance(struct gunyah_vm *ghvm, + struct gunyah_fn_desc *f) +{ + struct gunyah_vm_function_instance *inst, *iter; + void __user *user_argp; + void *argp __free(kfree) = NULL; + long r = 0; + + if (f->arg_size) { + argp = kzalloc(f->arg_size, GFP_KERNEL); + if (!argp) + return -ENOMEM; + + user_argp = u64_to_user_ptr(f->arg); + if (copy_from_user(argp, user_argp, f->arg_size)) + return -EFAULT; + } + + r = mutex_lock_interruptible(&ghvm->fn_lock); + if (r) + return r; + + r = -ENOENT; + list_for_each_entry_safe(inst, iter, &ghvm->functions, vm_list) { + if (inst->fn->type == f->type && + inst->fn->compare(inst, argp, f->arg_size)) { + gunyah_vm_remove_function_instance(inst); + r = 0; + } + } + + mutex_unlock(&ghvm->fn_lock); + return r; +} + +int gunyah_vm_function_register(struct gunyah_vm_function *fn) +{ + if (!fn->bind || !fn->unbind) + return -EINVAL; + + return xa_err(xa_store(&gunyah_vm_functions, fn->type, fn, GFP_KERNEL)); +} +EXPORT_SYMBOL_GPL(gunyah_vm_function_register); + +void gunyah_vm_function_unregister(struct gunyah_vm_function *fn) +{ + /* Expecting unregister to only come when unloading a module */ + WARN_ON(fn->mod && module_refcount(fn->mod)); + xa_erase(&gunyah_vm_functions, fn->type); +} +EXPORT_SYMBOL_GPL(gunyah_vm_function_unregister); + int gunyah_vm_add_resource_ticket(struct gunyah_vm *ghvm, struct gunyah_vm_resource_ticket *ticket) { @@ -198,7 +358,11 @@ static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) init_rwsem(&ghvm->status_lock); init_waitqueue_head(&ghvm->vm_status_wait); + kref_init(&ghvm->kref); ghvm->vm_status = GUNYAH_RM_VM_STATUS_NO_STATE; + + INIT_LIST_HEAD(&ghvm->functions); + mutex_init(&ghvm->fn_lock); mutex_init(&ghvm->resources_lock); INIT_LIST_HEAD(&ghvm->resources); INIT_LIST_HEAD(&ghvm->resource_tickets); @@ -311,6 +475,7 @@ static long gunyah_vm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct gunyah_vm *ghvm = filp->private_data; + void __user *argp = (void __user *)arg; long r; switch (cmd) { @@ -318,6 +483,24 @@ static long gunyah_vm_ioctl(struct file *filp, unsigned int cmd, r = gunyah_vm_ensure_started(ghvm); break; } + case GUNYAH_VM_ADD_FUNCTION: { + struct gunyah_fn_desc f; + + if (copy_from_user(&f, argp, sizeof(f))) + return -EFAULT; + + r = gunyah_vm_add_function_instance(ghvm, &f); + break; + } + case GUNYAH_VM_REMOVE_FUNCTION: { + struct gunyah_fn_desc f; + + if (copy_from_user(&f, argp, sizeof(f))) + return -EFAULT; + + r = gunyah_vm_rm_function_instance(ghvm, &f); + break; + } default: r = -ENOTTY; break; @@ -326,9 +509,15 @@ static long gunyah_vm_ioctl(struct file *filp, unsigned int cmd, return r; } -static int gunyah_vm_release(struct inode *inode, struct file *filp) +int __must_check gunyah_vm_get(struct gunyah_vm *ghvm) { - struct gunyah_vm *ghvm = filp->private_data; + return kref_get_unless_zero(&ghvm->kref); +} +EXPORT_SYMBOL_GPL(gunyah_vm_get); + +static void _gunyah_vm_put(struct kref *kref) +{ + struct gunyah_vm *ghvm = container_of(kref, struct gunyah_vm, kref); int ret; /** @@ -338,6 +527,7 @@ static int gunyah_vm_release(struct inode *inode, struct file *filp) if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_RUNNING) gunyah_vm_stop(ghvm); + gunyah_vm_remove_functions(ghvm); gunyah_vm_clean_resources(ghvm); if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_EXITED || @@ -364,6 +554,19 @@ static int gunyah_vm_release(struct inode *inode, struct file *filp) gunyah_rm_put(ghvm->rm); kfree(ghvm); +} + +void gunyah_vm_put(struct gunyah_vm *ghvm) +{ + kref_put(&ghvm->kref, _gunyah_vm_put); +} +EXPORT_SYMBOL_GPL(gunyah_vm_put); + +static int gunyah_vm_release(struct inode *inode, struct file *filp) +{ + struct gunyah_vm *ghvm = filp->private_data; + + gunyah_vm_put(ghvm); return 0; } diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index 0d291f7228859..190a95ee8da64 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -7,6 +7,8 @@ #define _GUNYAH_VM_MGR_PRIV_H #include +#include +#include #include #include @@ -26,6 +28,10 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, * @vm_status: Current state of the VM, as last reported by RM * @vm_status_wait: Wait queue for status @vm_status changes * @status_lock: Serializing state transitions + * @kref: Reference counter for VM functions + * @fn_lock: Serialization addition of functions + * @functions: List of &struct gunyah_vm_function_instance that have been + * created by user for this VM. * @resource_lock: Serializing addition of resources and resource tickets * @resources: List of &struct gunyah_resource that are associated with this VM * @resource_tickets: List of &struct gunyah_vm_resource_ticket @@ -42,6 +48,10 @@ struct gunyah_vm { enum gunyah_rm_vm_status vm_status; wait_queue_head_t vm_status_wait; struct rw_semaphore status_lock; + + struct kref kref; + struct mutex fn_lock; + struct list_head functions; struct mutex resources_lock; struct list_head resources; struct list_head resource_tickets; diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 0017691002607..18ecebf41a3ff 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -11,8 +11,92 @@ #include #include #include +#include #include +#include + +struct gunyah_vm; + +int __must_check gunyah_vm_get(struct gunyah_vm *ghvm); +void gunyah_vm_put(struct gunyah_vm *ghvm); + +struct gunyah_vm_function_instance; +/** + * struct gunyah_vm_function - Represents a function type + * @type: value from &enum gunyah_fn_type + * @name: friendly name for debug purposes + * @mod: owner of the function type + * @bind: Called when a new function of this type has been allocated. + * @unbind: Called when the function instance is being destroyed. + * @compare: Compare function instance @f's argument to the provided arg. + * Return true if they are equivalent. Used on GUNYAH_VM_REMOVE_FUNCTION. + */ +struct gunyah_vm_function { + u32 type; + const char *name; + struct module *mod; + long (*bind)(struct gunyah_vm_function_instance *f); + void (*unbind)(struct gunyah_vm_function_instance *f); + bool (*compare)(const struct gunyah_vm_function_instance *f, + const void *arg, size_t size); +}; + +/** + * struct gunyah_vm_function_instance - Represents one function instance + * @arg_size: size of user argument + * @argp: pointer to user argument + * @ghvm: Pointer to VM instance + * @rm: Pointer to resource manager for the VM instance + * @fn: The ops for the function + * @data: Private data for function + * @vm_list: for gunyah_vm's functions list + */ +struct gunyah_vm_function_instance { + size_t arg_size; + void *argp; + struct gunyah_vm *ghvm; + struct gunyah_rm *rm; + struct gunyah_vm_function *fn; + void *data; + struct list_head vm_list; +}; + +int gunyah_vm_function_register(struct gunyah_vm_function *f); +void gunyah_vm_function_unregister(struct gunyah_vm_function *f); + +/* Since the function identifiers were setup in a uapi header as an + * enum and we do no want to change that, the user must supply the expanded + * constant as well and the compiler checks they are the same. + * See also MODULE_ALIAS_RDMA_NETLINK. + */ +#define MODULE_ALIAS_GUNYAH_VM_FUNCTION(_type, _idx) \ + static inline void __maybe_unused __chk##_idx(void) \ + { \ + BUILD_BUG_ON(_type != _idx); \ + } \ + MODULE_ALIAS("ghfunc:" __stringify(_idx)) + +#define DECLARE_GUNYAH_VM_FUNCTION(_name, _type, _bind, _unbind, _compare) \ + static struct gunyah_vm_function _name = { \ + .type = _type, \ + .name = __stringify(_name), \ + .mod = THIS_MODULE, \ + .bind = _bind, \ + .unbind = _unbind, \ + .compare = _compare, \ + } + +#define module_gunyah_vm_function(__gf) \ + module_driver(__gf, gunyah_vm_function_register, \ + gunyah_vm_function_unregister) + +#define DECLARE_GUNYAH_VM_FUNCTION_INIT(_name, _type, _idx, _bind, _unbind, \ + _compare) \ + DECLARE_GUNYAH_VM_FUNCTION(_name, _type, _bind, _unbind, _compare); \ + module_gunyah_vm_function(_name); \ + MODULE_ALIAS_GUNYAH_VM_FUNCTION(_type, _idx) + /* Matches resource manager's resource types for VM_GET_HYP_RESOURCES RPC */ enum gunyah_resource_type { /* clang-format off */ @@ -35,8 +119,6 @@ struct gunyah_resource { u32 rm_label; }; -struct gunyah_vm; - /** * struct gunyah_vm_resource_ticket - Represents a ticket to reserve access to VM resource(s) * @vm_list: for @gunyah_vm->resource_tickets diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index 31e7f79a6c398..1b7cb5fde70a2 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -25,4 +25,22 @@ */ #define GUNYAH_VM_START _IO(GUNYAH_IOCTL_TYPE, 0x3) +#define GUNYAH_FN_MAX_ARG_SIZE 256 + +/** + * struct gunyah_fn_desc - Arguments to create a VM function + * @type: Type of the function. See &enum gunyah_fn_type. + * @arg_size: Size of argument to pass to the function. arg_size <= GUNYAH_FN_MAX_ARG_SIZE + * @arg: Pointer to argument given to the function. See &enum gunyah_fn_type for expected + * arguments for a function type. + */ +struct gunyah_fn_desc { + __u32 type; + __u32 arg_size; + __u64 arg; +}; + +#define GUNYAH_VM_ADD_FUNCTION _IOW(GUNYAH_IOCTL_TYPE, 0x4, struct gunyah_fn_desc) +#define GUNYAH_VM_REMOVE_FUNCTION _IOW(GUNYAH_IOCTL_TYPE, 0x7, struct gunyah_fn_desc) + #endif From patchwork Thu Feb 22 23:16:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568234 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB9A9C47DD9 for ; Thu, 22 Feb 2024 23:17:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7F2F6B008C; Thu, 22 Feb 2024 18:16:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B03A26B0096; Thu, 22 Feb 2024 18:16:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90B486B0098; Thu, 22 Feb 2024 18:16:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7BCB56B008C for ; Thu, 22 Feb 2024 18:16:46 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 50D87A1771 for ; Thu, 22 Feb 2024 23:16:46 +0000 (UTC) X-FDA: 81821001612.19.1620874 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf11.hostedemail.com (Postfix) with ESMTP id 2B11C40005 for ; Thu, 22 Feb 2024 23:16:44 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=We7DYilB; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643804; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qpqdFemGGFJkjOEURdTOzVY4PBnSlU3kwov4k+Wn9r0=; b=RqJIxKl0/ORtauJYjaMT3x+NNGzVlfRtbQxJovpHHMd0Upb/uFWW2KpJUOFuM2XIBvtISK QKLvrr2mRIArKlGobNSVVX1w6WHPTE6h3jRuH6obeA8v00saeE4qoAjB4NCK+NeqQx1Gkq JMmOAcfUAFNWySNsRhbLqtVW+/Expq4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=We7DYilB; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643804; a=rsa-sha256; cv=none; b=XyndPzNikmNRaASDEftMDGciLceu/jOzUXofJxJ40VaCi6kouVEGYXCJM/dZ8rzqQ2iiNA YU5yrjOIBQfu4gRtHN5qQxgRdiZhlwa3gzLLLrOe2PfTfwhsVmzRUvK4WiV5IXPjB92Q9E Wjrl82hG74kXZ9CTN6kw55JXvOPjurc= Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLiPtL021602; Thu, 22 Feb 2024 23:16:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=qpqdFemGGFJkjOEURdTOzVY4PBnSlU3kwov4k+Wn9r0 =; b=We7DYilBpy08K7/xknPD35U3nqsWufZYKODVFk2NxJd+u8ZVF7g56A+9QAU 9LUwNK/gmcLOt4HmdTA5BspuBTaY3mXnAjcuZSuZ6aCH2t1vWe03jedAvPNT9NoV m8SXoEbo7XQVxRN7xmAwc733zu5U+4cfFPnmRATuNhqgXrqJnvsxEMX7H+uwUqQb SfQNfcyDjAVK+GvP3x/szQn+pPOgSzqbBSQxq8lrTeUc/VNXuwyVsgnpK+M+T6RZ 308XBsyk1CICW2pjJi54++2MSIifBLyTt3y+a/gaXTlyWvCuIxakQdt1Zbyore3N zeM1HfksjMEta/6iKltfSQ5noDQ== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we2kf9puj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:36 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGZjM017474 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:35 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:34 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:37 -0800 Subject: [PATCH v17 14/35] virt: gunyah: Add hypercalls for running a vCPU MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-14-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 1Ifkr26tkeB9TdkcC50PB1_JgTfOYFy7 X-Proofpoint-GUID: 1Ifkr26tkeB9TdkcC50PB1_JgTfOYFy7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=0 phishscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=556 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Stat-Signature: 4xfbq7o6p3rr88fr6ja417x6sjbdeodf X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2B11C40005 X-HE-Tag: 1708643804-946649 X-HE-Meta: U2FsdGVkX1/sUy9dMZOVaUUMuFG0ZBTTYLq59xqpcSsTBwnk/emBTP6K9z8NjiPWeUG03wg91uZF9ujlVP6bQvHQPaM33fTKLtSjwt6zMKO0ZHwNFf0Lsgsm8q9r0UW1+h+psbmmr1CCaq8i4OEnFQ2keaoRVEciPKqVEtHbojTrZa2uJKf+kFVTlmF195pQ0IpdK5v3VTnKYVPiiEhMJyiOOWkm8IqtZaFsbqpy/hlhbSNIeON4DkVnGvuWaJDdpH8OHPs5qs2xG+xjxx6GwkPRHCRardOjhTicPi5B1NYcW36b4RPtvsrRmCh2+9jznTG6S6Hgbt+kt+0uCGu9MarnWyOBv6EHr/EtYvEm1R5TDd6hsLJeISJuCAahrMzGNb+zyu+E2zOS6/dDzIYM4RJ8NSkGSh4MxX/ukxVkWhcxac82WlRXtnlzbWYGOdj/b5GDLIHOYgVFrCtpsGpdFY2m05xXCxR2TYSU6Ri0k5AYX+mF6zelXHd7iRY6cvBPMxWhbF+3F2QW2UWmlikIWHrErIRHCny0fUl+tbmcEkSg6iXA0HAr4wydckh4HJr9eYLWuVPKqwB/NxWplTumTRizt73DSaw0jzbtf2v9e5vV8tkhYpFY/4RHoh53tnRVPLPxStsyMAMK84kv8oAQIvv1tepKgPfISYpzK3x7uFGHYjQIGV5fYUWBStxrx3kDECRv91bio5Tt4cT8dBkSkuY4hQ8czeWofaSXAw5xNc+hVCgAO38L5g0oe9AvsHU8CTabRFYl0OMeLi0sJQn3ZYXcbqu+4Brhfdr6bQ3cpIUb7fqP/Cac/9RpuFzhoY0TnE9VeUwXHb+ckPaw+sgRD6JbxRYimw9Tm2OyY0QcChJj6Z8PVpADtDR6UkLIhUgQjN5XOSZKJqKXu+y4yWGtcG5JvURKlxH9jrYzOeIsJRzjCM7pp0yk2trgyTKYaqUVo0bU/X2gBoeDGTNX0VX y6HweMcM xsAoYsv8ve1kFTVnhrbnUsPqOpZuqJ30bMYVtIoDQ1cjxlmxL8v9lDhxLG3Fnccpxo237vBtJ+2sqCNMXKgnvCn6Z27enllhu8OtvIH4w7XyfTd/G9cWUyp5X5nOLyvE8f0KWZFvk+5CvvtwlYGU2T7a8gcutVgLKzo8B2Ock10lx2Ntx0OlgJaMKWF+nZ3JKp5cIZzadqnEpBzBWoAVZWcPw2aX2BLNReAKuMVTRfuaK4esklIhtqoeo3NdGh91TmYX0ELim8bmLLzyKg2Gy4ujAk8miGabA6ngBhKg4gGk9SexrJpcdJmYZPZU5siea8QIrbgKJGRWHpWP4MnFYSn6g9iTeHfxH8jCVXluPzTt2+5/cZzthBwSxn1jaZXbThQjSMWCab3A7juBp/aCKZXoLrQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add hypercall to donate CPU time to a vCPU. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- arch/arm64/gunyah/gunyah_hypercall.c | 37 ++++++++++++++++++++++++++++++++++++ include/linux/gunyah.h | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/arch/arm64/gunyah/gunyah_hypercall.c b/arch/arm64/gunyah/gunyah_hypercall.c index 1302e128be6e9..fee21df42c176 100644 --- a/arch/arm64/gunyah/gunyah_hypercall.c +++ b/arch/arm64/gunyah/gunyah_hypercall.c @@ -39,6 +39,7 @@ EXPORT_SYMBOL_GPL(arch_is_gunyah_guest); #define GUNYAH_HYPERCALL_HYP_IDENTIFY GUNYAH_HYPERCALL(0x8000) #define GUNYAH_HYPERCALL_MSGQ_SEND GUNYAH_HYPERCALL(0x801B) #define GUNYAH_HYPERCALL_MSGQ_RECV GUNYAH_HYPERCALL(0x801C) +#define GUNYAH_HYPERCALL_VCPU_RUN GUNYAH_HYPERCALL(0x8065) /* clang-format on */ /** @@ -113,5 +114,41 @@ enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size, } EXPORT_SYMBOL_GPL(gunyah_hypercall_msgq_recv); +/** + * gunyah_hypercall_vcpu_run() - Donate CPU time to a vcpu + * @capid: capability ID of the vCPU to run + * @resume_data: Array of 3 state-specific resume data + * @resp: Filled reason why vCPU exited when return value is GUNYAH_ERROR_OK + * + * See also: + * https://github.com/quic/gunyah-hypervisor/blob/develop/docs/api/gunyah_api.md#run-a-proxy-scheduled-vcpu-thread + */ +enum gunyah_error +gunyah_hypercall_vcpu_run(u64 capid, unsigned long *resume_data, + struct gunyah_hypercall_vcpu_run_resp *resp) +{ + struct arm_smccc_1_2_regs args = { + .a0 = GUNYAH_HYPERCALL_VCPU_RUN, + .a1 = capid, + .a2 = resume_data[0], + .a3 = resume_data[1], + .a4 = resume_data[2], + /* C language says this will be implictly zero. Gunyah requires 0, so be explicit */ + .a5 = 0, + }; + struct arm_smccc_1_2_regs res; + + arm_smccc_1_2_hvc(&args, &res); + if (res.a0 == GUNYAH_ERROR_OK) { + resp->sized_state = res.a1; + resp->state_data[0] = res.a2; + resp->state_data[1] = res.a3; + resp->state_data[2] = res.a4; + } + + return res.a0; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_vcpu_run); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls"); diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 18ecebf41a3ff..6c24544f38dc9 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -273,4 +273,39 @@ enum gunyah_error gunyah_hypercall_msgq_send(u64 capid, size_t size, void *buff, enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size, size_t *recv_size, bool *ready); +struct gunyah_hypercall_vcpu_run_resp { + union { + enum { + /* clang-format off */ + /* VCPU is ready to run */ + GUNYAH_VCPU_STATE_READY = 0, + /* VCPU is sleeping until an interrupt arrives */ + GUNYAH_VCPU_STATE_EXPECTS_WAKEUP = 1, + /* VCPU is powered off */ + GUNYAH_VCPU_STATE_POWERED_OFF = 2, + /* VCPU is blocked in EL2 for unspecified reason */ + GUNYAH_VCPU_STATE_BLOCKED = 3, + /* VCPU has returned for MMIO READ */ + GUNYAH_VCPU_ADDRSPACE_VMMIO_READ = 4, + /* VCPU has returned for MMIO WRITE */ + GUNYAH_VCPU_ADDRSPACE_VMMIO_WRITE = 5, + /* VCPU blocked on fault where we can demand page */ + GUNYAH_VCPU_ADDRSPACE_PAGE_FAULT = 7, + /* clang-format on */ + } state; + u64 sized_state; + }; + u64 state_data[3]; +}; + +enum { + GUNYAH_ADDRSPACE_VMMIO_ACTION_EMULATE = 0, + GUNYAH_ADDRSPACE_VMMIO_ACTION_RETRY = 1, + GUNYAH_ADDRSPACE_VMMIO_ACTION_FAULT = 2, +}; + +enum gunyah_error +gunyah_hypercall_vcpu_run(u64 capid, unsigned long *resume_data, + struct gunyah_hypercall_vcpu_run_resp *resp); + #endif From patchwork Thu Feb 22 23:16:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D850C47DD9 for ; Thu, 22 Feb 2024 23:17:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4E9E6B009D; Thu, 22 Feb 2024 18:16:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A42C76B009E; Thu, 22 Feb 2024 18:16:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 427516B00A1; Thu, 22 Feb 2024 18:16:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9653C6B009A for ; Thu, 22 Feb 2024 18:16:48 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 765D2121050 for ; Thu, 22 Feb 2024 23:16:48 +0000 (UTC) X-FDA: 81821001696.11.E0E5977 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf01.hostedemail.com (Postfix) with ESMTP id 3BE9140016 for ; Thu, 22 Feb 2024 23:16:46 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=bbg5NMAx; spf=pass (imf01.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643806; a=rsa-sha256; cv=none; b=F/I2kL/Jtm73BXhJHq8DystRy4FYAT2TJLbZnCHJpKgaDtMK9Ulr3Z0VjHZzaexRd3xvSn 7WAlbEtWE0B1LZujZncVKGaXBxTp46kfJV5hJq954shtbFpe5thKt7sWp78rd4ev7M2VQU P+FlnMtZ0f3ZTG7E4o5C05Z2OHBR26Q= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=bbg5NMAx; spf=pass (imf01.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643806; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fu9VYODTCr0GEoUe6Jrsd0IZl9THqRBQ+zaO5VcM3G4=; b=4aCZMtaerdoSFQDaqL497Cvp6vXrqIVcn+BISxOud8ljp3NiQmH1hZms9vAMne0Ep4MNJF 2a7zeAJ8QZTZvDGV21l3CpFMUFwwFWA0AVENTzJy3Uw/1aAScUVOTFgGwRAqqRGj5DSTHs rWspE4bjlEKOl6hvSdNLiHS87Xmh1AY= Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMT7FW012015; Thu, 22 Feb 2024 23:16:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=fu9VYODTCr0GEoUe6Jrsd0IZl9THqRBQ+zaO5VcM3G4 =; b=bbg5NMAxbDzoZiksJUK4QN0BsT3WQOEWRoA0DxPYroBvGL5eIsbthgowfDQ UgwEn+Vnm8/hcT8g15V3S3+ImBA6bDv3jgMYfqmpArQPsM7dQ9JrGedjNRuS6f58 4byFmMAxccXcJrREdjWI1wGXrBmm1o3oI9NliGWICavLlE/ayqwkCS6jylaAAFBo 1Lt5vvPDYU53auGI+bYYmFO1SZYqJhluz8fg4xfDhMJEqosGxyTwV2RLKEt38vLi LfOzseAtpx4/fNTk3yddC26kXRzwIxe81P4hvZWJEMEwHGZO31/PxEBY7KbgxYfv /h/4Dsm6AYmcL/CcolS7VKVhAmQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we97tgf8e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:36 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGaO1027718 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:36 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:35 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:38 -0800 Subject: [PATCH v17 15/35] virt: gunyah: Add proxy-scheduled vCPUs MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-15-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: cKaRNTeRTBjgKbWCoHPWfLlIhD74EDHp X-Proofpoint-ORIG-GUID: cKaRNTeRTBjgKbWCoHPWfLlIhD74EDHp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 adultscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3BE9140016 X-Stat-Signature: uqqktzmyk9bhiodtt44z7hg871fje7nm X-Rspam-User: X-HE-Tag: 1708643806-663393 X-HE-Meta: U2FsdGVkX1/a1eyEgsg75RW4h7OPrnv50mWgXbhEAEwrr/5nIlVTwKrZphmEjUmIUGxqaP1I3sOzCGYOymePSfarvUNUovS6VBUvBoSp5WABHJN0OGZmlHvtjN0/EQv1nrkJma6RY/ijrF8WkqnuSbFjgHCl5Rt09edcT+/VIlOlyky2GfIU/oIEAOeiYcXDJA11okDvvvF0wX9KWxobJUWR/vSkB2mToWEOcOJdBiP3eyJ1wljuubDDGLVWKMh2ciGxSosUoE7PIm9/+xnJGnu0uv9AdHndYBFuygVlDINpeQEZdzO/8jdjMjXKHrPYBi0f+Dh8ITIMEVaJywl+NB/PpK+xOoah6eS5CLMdr+TI2+fX+mVN2miE9UKbgmFf7URwVyaMlJD0GEXFwYicxOOOd3Y2cgLplc7PwPeel48uRohG1aMHF/XO40xbtE9a+UeImZ27Ge+TrBSpN0OV/gh06RFebAZ3v90sWM23oxLSLFed1YMtvpYiNMbkWHx231h6Qge2/GbEdqlq5TxS2eiMBDMTcBhfT/bqY7mNmvT3HC4R6VZRs1FYKLfs6Nh/ksQysWd3GsD86BNmrMhGMaOUFdt/5R0coJGYu1McfRL8A3hnwtqnRmL+4YHKZiM/dik7zScQkDwnvs/PMxJ3kZhYKruhYgUOmr0ProcWKnnzwoY5OMEWSq+TqfPjuSVFvdduMzGxIdllxvD4BU62WEF/yPX/j+WCxWb8wJtPMODkFg16ANL989sk32mqJqy3FXOKSMAfw5QJKazsrQV1g1y8AS/z8HvJmACFr3IEY6nSLVFAACcSlCi5ZacwX9FHmWJALIFBk0t4y7WopnjC1hYxP2wf076vtesRUTzQcomX2b9kcKw4Ve76xslCzGpLuYLY+/LDh1vTy8lxFBursfwclCdQ5qvwtQQVMBGTJlecjfD1AzTuk2/TQfpkFTtZBXA4PYZz3hTNXNNP/z+ s3CFKPKz HAU5osKLO7hiX13wQ8BpzZO0p5K/iUDlRFD/jltv6RB+Mwb5Ux5SFUbj20/bJiNshBgMlPFj3KsY5EpO1nBLRaee+5Qn/UkQUALj8dhy33purdGdAwpgYnCWyhHeMrh7+D38ACDhHNdbBrMWkiIVvezFIJwJQ7M0eHrcMOnmUjL1QzGXVdl4Kg5a/mcCW7yu93PmimspgK9/NiplLo/mE9uNNr65JWKII/glj48ahCMGkSPVwf4mbrVP8s97YRCKDEiPmk4FPM4ALXizEsO4i6/SbRSgrzlS4H9y21+xWg8d/AdosQ5AnSx1B+FR4G8rTITefbRspnM7g8lHHrDjji9ng1WiSinCwS58Tu5OoLhZRXAAl5VvmFJPD+eeRtiJwqPYnVb25+C62QjTT4a5KaJtyjw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Gunyah allows vCPUs that are configured as proxy-scheduled to be scheduled by another virtual machine (host) that holds capabilities to those vCPUs with suitable rights. Gunyah also supports configuring regions of a proxy-scheduled VM's address space to be virtualized by the host VM. This permits a host VMM to emulate MMIO devices in the proxy-scheduled VM. vCPUs are presented to the host as a Gunyah resource and represented to userspace as a Gunyah VM function. Creating the vcpu function on the VM will create a file descriptor that: - can handle an ioctl to run the vCPU. When called, Gunyah will directly context-switch to the selected vCPU and run it until one of the following events occurs: * the host vcpu's time slice ends * the host vcpu receives an interrupt or would have been pre-empted by the hypervisor * a fault occurs in the proxy-scheduled vcpu * a power management event, such as idle or cpu-off call in the vcpu - can be mmap'd to share the gunyah_vcpu_run structure with userspace. This allows the vcpu_run result codes to be accessed, and for arguments to vcpu_run to be passed, e.g. for resuming the vcpu when handling certain fault and exit cases. Co-developed-by: Prakruthi Deepak Heragu Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- drivers/virt/gunyah/Makefile | 2 +- drivers/virt/gunyah/gunyah_vcpu.c | 561 ++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/vm_mgr.c | 5 + drivers/virt/gunyah/vm_mgr.h | 2 + include/uapi/linux/gunyah.h | 163 +++++++++++ 5 files changed, 732 insertions(+), 1 deletion(-) diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index 47f1fae5419bf..3f82af8c5ce79 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -2,4 +2,4 @@ gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o -obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o +obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o gunyah_vcpu.o diff --git a/drivers/virt/gunyah/gunyah_vcpu.c b/drivers/virt/gunyah/gunyah_vcpu.c new file mode 100644 index 0000000000000..8192350f180b0 --- /dev/null +++ b/drivers/virt/gunyah/gunyah_vcpu.c @@ -0,0 +1,561 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vm_mgr.h" + +#include + +#define MAX_VCPU_NAME 20 /* gh-vcpu:strlen(U32::MAX)+NUL */ + +/** + * struct gunyah_vcpu - Track an instance of gunyah vCPU + * @f: Function instance (how we get associated with the main VM) + * @rsc: Pointer to the Gunyah vCPU resource, will be NULL until VM starts + * @run_lock: One userspace thread at a time should run the vCPU + * @ghvm: Pointer to the main VM struct; quicker look up than going through + * @f->ghvm + * @vcpu_run: Pointer to page shared with userspace to communicate vCPU state + * @state: Our copy of the state of the vCPU, since userspace could trick + * kernel to behave incorrectly if we relied on @vcpu_run + * @mmio_read_len: Our copy of @vcpu_run->mmio.len; see also @state + * @mmio_addr: Our copy of @vcpu_run->mmio.phys_addr; see also @state + * @ready: if vCPU goes to sleep, hypervisor reports to us that it's sleeping + * and will signal interrupt (from @rsc) when it's time to wake up. + * This completion signals that we can run vCPU again. + * @nb: When VM exits, the status of VM is reported via @vcpu_run->status. + * We need to track overall VM status, and the nb gives us the updates from + * Resource Manager. + * @ticket: resource ticket to claim vCPU# for the VM + * @kref: Reference counter + */ +struct gunyah_vcpu { + struct gunyah_vm_function_instance *f; + struct gunyah_resource *rsc; + struct mutex run_lock; + struct gunyah_vm *ghvm; + + struct gunyah_vcpu_run *vcpu_run; + + /** + * Track why the vcpu_run hypercall returned. This mirrors the vcpu_run + * structure shared with userspace, except is used internally to avoid + * trusting userspace to not modify the vcpu_run structure. + */ + enum { + GUNYAH_VCPU_RUN_STATE_UNKNOWN = 0, + GUNYAH_VCPU_RUN_STATE_READY, + GUNYAH_VCPU_RUN_STATE_MMIO_READ, + GUNYAH_VCPU_RUN_STATE_MMIO_WRITE, + GUNYAH_VCPU_RUN_STATE_SYSTEM_DOWN, + } state; + u8 mmio_read_len; + u64 mmio_addr; + + struct completion ready; + + struct notifier_block nb; + struct gunyah_vm_resource_ticket ticket; + struct kref kref; +}; + +static void vcpu_release(struct kref *kref) +{ + struct gunyah_vcpu *vcpu = container_of(kref, struct gunyah_vcpu, kref); + + free_page((unsigned long)vcpu->vcpu_run); + kfree(vcpu); +} + +/* + * When hypervisor allows us to schedule vCPU again, it gives us an interrupt + */ +static irqreturn_t gunyah_vcpu_irq_handler(int irq, void *data) +{ + struct gunyah_vcpu *vcpu = data; + + complete(&vcpu->ready); + return IRQ_HANDLED; +} + +static void gunyah_handle_page_fault( + struct gunyah_vcpu *vcpu, + const struct gunyah_hypercall_vcpu_run_resp *vcpu_run_resp) +{ + u64 addr = vcpu_run_resp->state_data[0]; + + vcpu->vcpu_run->page_fault.resume_action = GUNYAH_VCPU_RESUME_FAULT; + vcpu->vcpu_run->page_fault.attempt = 0; + vcpu->vcpu_run->page_fault.phys_addr = addr; + vcpu->vcpu_run->exit_reason = GUNYAH_VCPU_EXIT_PAGE_FAULT; +} + +static void +gunyah_handle_mmio(struct gunyah_vcpu *vcpu, + const struct gunyah_hypercall_vcpu_run_resp *vcpu_run_resp) +{ + u64 addr = vcpu_run_resp->state_data[0], + len = vcpu_run_resp->state_data[1], + data = vcpu_run_resp->state_data[2]; + + if (WARN_ON(len > sizeof(u64))) + len = sizeof(u64); + + if (vcpu_run_resp->state == GUNYAH_VCPU_ADDRSPACE_VMMIO_READ) { + vcpu->vcpu_run->mmio.is_write = 0; + /* Record that we need to give vCPU user's supplied value next gunyah_vcpu_run() */ + vcpu->state = GUNYAH_VCPU_RUN_STATE_MMIO_READ; + vcpu->mmio_read_len = len; + } else { /* GUNYAH_VCPU_ADDRSPACE_VMMIO_WRITE */ + vcpu->vcpu_run->mmio.is_write = 1; + memcpy(vcpu->vcpu_run->mmio.data, &data, len); + vcpu->state = GUNYAH_VCPU_RUN_STATE_MMIO_WRITE; + } + + /* Assume userspace is okay and handles the access due to existing userspace */ + vcpu->vcpu_run->mmio.resume_action = GUNYAH_VCPU_RESUME_HANDLED; + vcpu->mmio_addr = vcpu->vcpu_run->mmio.phys_addr = addr; + vcpu->vcpu_run->mmio.len = len; + vcpu->vcpu_run->exit_reason = GUNYAH_VCPU_EXIT_MMIO; +} + +static int gunyah_handle_mmio_resume(struct gunyah_vcpu *vcpu, + unsigned long resume_data[3]) +{ + switch (vcpu->vcpu_run->mmio.resume_action) { + case GUNYAH_VCPU_RESUME_HANDLED: + if (vcpu->state == GUNYAH_VCPU_RUN_STATE_MMIO_READ) { + if (unlikely(vcpu->mmio_read_len > + sizeof(resume_data[0]))) + vcpu->mmio_read_len = sizeof(resume_data[0]); + memcpy(&resume_data[0], vcpu->vcpu_run->mmio.data, + vcpu->mmio_read_len); + } + resume_data[1] = GUNYAH_ADDRSPACE_VMMIO_ACTION_EMULATE; + break; + case GUNYAH_VCPU_RESUME_FAULT: + resume_data[1] = GUNYAH_ADDRSPACE_VMMIO_ACTION_FAULT; + break; + case GUNYAH_VCPU_RESUME_RETRY: + resume_data[1] = GUNYAH_ADDRSPACE_VMMIO_ACTION_RETRY; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int gunyah_vcpu_rm_notification(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct gunyah_vcpu *vcpu = container_of(nb, struct gunyah_vcpu, nb); + struct gunyah_rm_vm_exited_payload *exit_payload = data; + + /* Wake up userspace waiting for the vCPU to be runnable again */ + if (action == GUNYAH_RM_NOTIFICATION_VM_EXITED && + le16_to_cpu(exit_payload->vmid) == vcpu->ghvm->vmid) + complete(&vcpu->ready); + + return NOTIFY_OK; +} + +static inline enum gunyah_vm_status +remap_vm_status(enum gunyah_rm_vm_status rm_status) +{ + switch (rm_status) { + case GUNYAH_RM_VM_STATUS_INIT_FAILED: + return GUNYAH_VM_STATUS_LOAD_FAILED; + case GUNYAH_RM_VM_STATUS_EXITED: + return GUNYAH_VM_STATUS_EXITED; + default: + return GUNYAH_VM_STATUS_CRASHED; + } +} + +/** + * gunyah_vcpu_check_system() - Check whether VM as a whole is running + * @vcpu: Pointer to gunyah_vcpu + * + * Returns true if the VM is alive. + * Returns false if the vCPU is the VM is not alive (can only be that VM is shutting down). + */ +static bool gunyah_vcpu_check_system(struct gunyah_vcpu *vcpu) + __must_hold(&vcpu->run_lock) +{ + bool ret = true; + + down_read(&vcpu->ghvm->status_lock); + if (likely(vcpu->ghvm->vm_status == GUNYAH_RM_VM_STATUS_RUNNING)) + goto out; + + vcpu->vcpu_run->status.status = remap_vm_status(vcpu->ghvm->vm_status); + vcpu->vcpu_run->status.exit_info = vcpu->ghvm->exit_info; + vcpu->vcpu_run->exit_reason = GUNYAH_VCPU_EXIT_STATUS; + vcpu->state = GUNYAH_VCPU_RUN_STATE_SYSTEM_DOWN; + ret = false; +out: + up_read(&vcpu->ghvm->status_lock); + return ret; +} + +/** + * gunyah_vcpu_run() - Request Gunyah to begin scheduling this vCPU. + * @vcpu: The client descriptor that was obtained via gunyah_vcpu_alloc() + */ +static int gunyah_vcpu_run(struct gunyah_vcpu *vcpu) +{ + struct gunyah_hypercall_vcpu_run_resp vcpu_run_resp; + unsigned long resume_data[3] = { 0 }; + enum gunyah_error gunyah_error; + int ret = 0; + + if (!vcpu->f) + return -ENODEV; + + if (mutex_lock_interruptible(&vcpu->run_lock)) + return -ERESTARTSYS; + + if (!vcpu->rsc) { + ret = -ENODEV; + goto out; + } + + switch (vcpu->state) { + case GUNYAH_VCPU_RUN_STATE_UNKNOWN: + if (vcpu->ghvm->vm_status != GUNYAH_RM_VM_STATUS_RUNNING) { + /** + * Check if VM is up. If VM is starting, will block + * until VM is fully up since that thread does + * down_write. + */ + if (!gunyah_vcpu_check_system(vcpu)) + goto out; + } + vcpu->state = GUNYAH_VCPU_RUN_STATE_READY; + break; + case GUNYAH_VCPU_RUN_STATE_MMIO_READ: + case GUNYAH_VCPU_RUN_STATE_MMIO_WRITE: + ret = gunyah_handle_mmio_resume(vcpu, resume_data); + if (ret) + goto out; + vcpu->state = GUNYAH_VCPU_RUN_STATE_READY; + break; + case GUNYAH_VCPU_RUN_STATE_SYSTEM_DOWN: + goto out; + default: + break; + } + + while (!ret && !signal_pending(current)) { + if (vcpu->vcpu_run->immediate_exit) { + ret = -EINTR; + goto out; + } + + gunyah_error = gunyah_hypercall_vcpu_run( + vcpu->rsc->capid, resume_data, &vcpu_run_resp); + if (gunyah_error == GUNYAH_ERROR_OK) { + memset(resume_data, 0, sizeof(resume_data)); + switch (vcpu_run_resp.state) { + case GUNYAH_VCPU_STATE_READY: + if (need_resched()) + schedule(); + break; + case GUNYAH_VCPU_STATE_POWERED_OFF: + /** + * vcpu might be off because the VM is shut down + * If so, it won't ever run again + */ + if (!gunyah_vcpu_check_system(vcpu)) + goto out; + /** + * Otherwise, another vcpu will turn it on (e.g. + * by PSCI) and hyp sends an interrupt to wake + * Linux up. + */ + fallthrough; + case GUNYAH_VCPU_STATE_EXPECTS_WAKEUP: + ret = wait_for_completion_interruptible( + &vcpu->ready); + /** + * reinitialize completion before next + * hypercall. If we reinitialize after the + * hypercall, interrupt may have already come + * before re-initializing the completion and + * then end up waiting for event that already + * happened. + */ + reinit_completion(&vcpu->ready); + /** + * Check VM status again. Completion + * might've come from VM exiting + */ + if (!ret && !gunyah_vcpu_check_system(vcpu)) + goto out; + break; + case GUNYAH_VCPU_STATE_BLOCKED: + schedule(); + break; + case GUNYAH_VCPU_ADDRSPACE_VMMIO_READ: + case GUNYAH_VCPU_ADDRSPACE_VMMIO_WRITE: + gunyah_handle_mmio(vcpu, &vcpu_run_resp); + goto out; + case GUNYAH_VCPU_ADDRSPACE_PAGE_FAULT: + gunyah_handle_page_fault(vcpu, &vcpu_run_resp); + goto out; + default: + pr_warn_ratelimited( + "Unknown vCPU state: %llx\n", + vcpu_run_resp.sized_state); + schedule(); + break; + } + } else if (gunyah_error == GUNYAH_ERROR_RETRY) { + schedule(); + } else { + ret = gunyah_error_remap(gunyah_error); + } + } + +out: + mutex_unlock(&vcpu->run_lock); + + if (signal_pending(current)) + return -ERESTARTSYS; + + return ret; +} + +static long gunyah_vcpu_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg) +{ + struct gunyah_vcpu *vcpu = filp->private_data; + long ret = -ENOTTY; + + switch (cmd) { + case GUNYAH_VCPU_RUN: + ret = gunyah_vcpu_run(vcpu); + break; + case GUNYAH_VCPU_MMAP_SIZE: + ret = PAGE_SIZE; + break; + default: + break; + } + return ret; +} + +static int gunyah_vcpu_release(struct inode *inode, struct file *filp) +{ + struct gunyah_vcpu *vcpu = filp->private_data; + + gunyah_vm_put(vcpu->ghvm); + kref_put(&vcpu->kref, vcpu_release); + return 0; +} + +static vm_fault_t gunyah_vcpu_fault(struct vm_fault *vmf) +{ + struct gunyah_vcpu *vcpu = vmf->vma->vm_file->private_data; + struct page *page; + + if (vmf->pgoff) + return VM_FAULT_SIGBUS; + + page = virt_to_page(vcpu->vcpu_run); + get_page(page); + vmf->page = page; + return 0; +} + +static const struct vm_operations_struct gunyah_vcpu_ops = { + .fault = gunyah_vcpu_fault, +}; + +static int gunyah_vcpu_mmap(struct file *file, struct vm_area_struct *vma) +{ + vma->vm_ops = &gunyah_vcpu_ops; + return 0; +} + +static const struct file_operations gunyah_vcpu_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = gunyah_vcpu_ioctl, + .release = gunyah_vcpu_release, + .llseek = noop_llseek, + .mmap = gunyah_vcpu_mmap, +}; + +static bool gunyah_vcpu_populate(struct gunyah_vm_resource_ticket *ticket, + struct gunyah_resource *ghrsc) +{ + struct gunyah_vcpu *vcpu = + container_of(ticket, struct gunyah_vcpu, ticket); + int ret; + + mutex_lock(&vcpu->run_lock); + if (vcpu->rsc) { + pr_warn("vcpu%d already got a Gunyah resource. Check if multiple resources with same label were configured.\n", + vcpu->ticket.label); + ret = -EEXIST; + goto out; + } + + vcpu->rsc = ghrsc; + + ret = request_irq(vcpu->rsc->irq, gunyah_vcpu_irq_handler, + IRQF_TRIGGER_RISING, "gunyah_vcpu", vcpu); + if (ret) { + pr_warn("Failed to request vcpu irq %d: %d", vcpu->rsc->irq, + ret); + goto out; + } + + enable_irq_wake(vcpu->rsc->irq); + +out: + mutex_unlock(&vcpu->run_lock); + return !ret; +} + +static void gunyah_vcpu_unpopulate(struct gunyah_vm_resource_ticket *ticket, + struct gunyah_resource *ghrsc) +{ + struct gunyah_vcpu *vcpu = + container_of(ticket, struct gunyah_vcpu, ticket); + + vcpu->vcpu_run->immediate_exit = true; + complete_all(&vcpu->ready); + mutex_lock(&vcpu->run_lock); + free_irq(vcpu->rsc->irq, vcpu); + vcpu->rsc = NULL; + mutex_unlock(&vcpu->run_lock); +} + +static long gunyah_vcpu_bind(struct gunyah_vm_function_instance *f) +{ + struct gunyah_fn_vcpu_arg *arg = f->argp; + struct gunyah_vcpu *vcpu; + char name[MAX_VCPU_NAME]; + struct file *file; + struct page *page; + int fd; + long r; + + if (f->arg_size != sizeof(*arg)) + return -EINVAL; + + vcpu = kzalloc(sizeof(*vcpu), GFP_KERNEL); + if (!vcpu) + return -ENOMEM; + + vcpu->f = f; + f->data = vcpu; + mutex_init(&vcpu->run_lock); + kref_init(&vcpu->kref); + init_completion(&vcpu->ready); + + page = alloc_page(GFP_KERNEL | __GFP_ZERO); + if (!page) { + r = -ENOMEM; + goto err_destroy_vcpu; + } + vcpu->vcpu_run = page_address(page); + + vcpu->ticket.resource_type = GUNYAH_RESOURCE_TYPE_VCPU; + vcpu->ticket.label = arg->id; + vcpu->ticket.owner = THIS_MODULE; + vcpu->ticket.populate = gunyah_vcpu_populate; + vcpu->ticket.unpopulate = gunyah_vcpu_unpopulate; + + r = gunyah_vm_add_resource_ticket(f->ghvm, &vcpu->ticket); + if (r) + goto err_destroy_page; + + if (!gunyah_vm_get(f->ghvm)) { + r = -ENODEV; + goto err_remove_resource_ticket; + } + vcpu->ghvm = f->ghvm; + + vcpu->nb.notifier_call = gunyah_vcpu_rm_notification; + /** + * Ensure we run after the vm_mgr handles the notification and does + * any necessary state changes. + */ + vcpu->nb.priority = -1; + r = gunyah_rm_notifier_register(f->rm, &vcpu->nb); + if (r) + goto err_put_gunyah_vm; + + kref_get(&vcpu->kref); + + fd = get_unused_fd_flags(O_CLOEXEC); + if (fd < 0) { + r = fd; + goto err_notifier; + } + + snprintf(name, sizeof(name), "gh-vcpu:%u", vcpu->ticket.label); + file = anon_inode_getfile(name, &gunyah_vcpu_fops, vcpu, O_RDWR); + if (IS_ERR(file)) { + r = PTR_ERR(file); + goto err_put_fd; + } + + fd_install(fd, file); + + return fd; +err_put_fd: + put_unused_fd(fd); +err_notifier: + gunyah_rm_notifier_unregister(f->rm, &vcpu->nb); +err_put_gunyah_vm: + gunyah_vm_put(vcpu->ghvm); +err_remove_resource_ticket: + gunyah_vm_remove_resource_ticket(f->ghvm, &vcpu->ticket); +err_destroy_page: + free_page((unsigned long)vcpu->vcpu_run); +err_destroy_vcpu: + kfree(vcpu); + return r; +} + +static void gunyah_vcpu_unbind(struct gunyah_vm_function_instance *f) +{ + struct gunyah_vcpu *vcpu = f->data; + + gunyah_rm_notifier_unregister(f->rm, &vcpu->nb); + gunyah_vm_remove_resource_ticket(vcpu->ghvm, &vcpu->ticket); + vcpu->f = NULL; + + kref_put(&vcpu->kref, vcpu_release); +} + +static bool gunyah_vcpu_compare(const struct gunyah_vm_function_instance *f, + const void *arg, size_t size) +{ + const struct gunyah_fn_vcpu_arg *instance = f->argp, *other = arg; + + if (sizeof(*other) != size) + return false; + + return instance->id == other->id; +} + +DECLARE_GUNYAH_VM_FUNCTION_INIT(vcpu, GUNYAH_FN_VCPU, 1, gunyah_vcpu_bind, + gunyah_vcpu_unbind, gunyah_vcpu_compare); +MODULE_DESCRIPTION("Gunyah vCPU Function"); +MODULE_LICENSE("GPL"); diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index a619dd10972a5..a6e25901dcea3 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -309,6 +309,11 @@ static int gunyah_vm_rm_notification_exited(struct gunyah_vm *ghvm, void *data) down_write(&ghvm->status_lock); ghvm->vm_status = GUNYAH_RM_VM_STATUS_EXITED; + ghvm->exit_info.type = le16_to_cpu(payload->exit_type); + ghvm->exit_info.reason_size = le32_to_cpu(payload->exit_reason_size); + memcpy(&ghvm->exit_info.reason, payload->exit_reason, + min(GUNYAH_VM_MAX_EXIT_REASON_SIZE, + ghvm->exit_info.reason_size)); up_write(&ghvm->status_lock); wake_up(&ghvm->vm_status_wait); diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index 190a95ee8da64..8c5b94101b2cf 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -28,6 +28,7 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, * @vm_status: Current state of the VM, as last reported by RM * @vm_status_wait: Wait queue for status @vm_status changes * @status_lock: Serializing state transitions + * @exit_info: Breadcrumbs why VM is not running anymore * @kref: Reference counter for VM functions * @fn_lock: Serialization addition of functions * @functions: List of &struct gunyah_vm_function_instance that have been @@ -48,6 +49,7 @@ struct gunyah_vm { enum gunyah_rm_vm_status vm_status; wait_queue_head_t vm_status_wait; struct rw_semaphore status_lock; + struct gunyah_vm_exit_info exit_info; struct kref kref; struct mutex fn_lock; diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index 1b7cb5fde70a2..46f7d3aa61d05 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -25,8 +25,33 @@ */ #define GUNYAH_VM_START _IO(GUNYAH_IOCTL_TYPE, 0x3) +/** + * enum gunyah_fn_type - Valid types of Gunyah VM functions + * @GUNYAH_FN_VCPU: create a vCPU instance to control a vCPU + * &struct gunyah_fn_desc.arg is a pointer to &struct gunyah_fn_vcpu_arg + * Return: file descriptor to manipulate the vcpu. + */ +enum gunyah_fn_type { + GUNYAH_FN_VCPU = 1, +}; + #define GUNYAH_FN_MAX_ARG_SIZE 256 +/** + * struct gunyah_fn_vcpu_arg - Arguments to create a vCPU. + * @id: vcpu id + * + * Create this function with &GUNYAH_VM_ADD_FUNCTION using type &GUNYAH_FN_VCPU. + * + * The vcpu type will register with the VM Manager to expect to control + * vCPU number `vcpu_id`. It returns a file descriptor allowing interaction with + * the vCPU. See the Gunyah vCPU API description sections for interacting with + * the Gunyah vCPU file descriptors. + */ +struct gunyah_fn_vcpu_arg { + __u32 id; +}; + /** * struct gunyah_fn_desc - Arguments to create a VM function * @type: Type of the function. See &enum gunyah_fn_type. @@ -43,4 +68,142 @@ struct gunyah_fn_desc { #define GUNYAH_VM_ADD_FUNCTION _IOW(GUNYAH_IOCTL_TYPE, 0x4, struct gunyah_fn_desc) #define GUNYAH_VM_REMOVE_FUNCTION _IOW(GUNYAH_IOCTL_TYPE, 0x7, struct gunyah_fn_desc) +/* + * ioctls for vCPU fds + */ + +/** + * enum gunyah_vm_status - Stores status reason why VM is not runnable (exited). + * @GUNYAH_VM_STATUS_LOAD_FAILED: VM didn't start because it couldn't be loaded. + * @GUNYAH_VM_STATUS_EXITED: VM requested shutdown/reboot. + * Use &struct gunyah_vm_exit_info.reason for further details. + * @GUNYAH_VM_STATUS_CRASHED: VM state is unknown and has crashed. + */ +enum gunyah_vm_status { + GUNYAH_VM_STATUS_LOAD_FAILED = 1, + GUNYAH_VM_STATUS_EXITED = 2, + GUNYAH_VM_STATUS_CRASHED = 3, +}; + +/* + * Gunyah presently sends max 4 bytes of exit_reason. + * If that changes, this macro can be safely increased without breaking + * userspace so long as struct gunyah_vcpu_run < PAGE_SIZE. + */ +#define GUNYAH_VM_MAX_EXIT_REASON_SIZE 8u + +/** + * struct gunyah_vm_exit_info - Reason for VM exit as reported by Gunyah + * See Gunyah documentation for values. + * @type: Describes how VM exited + * @padding: padding bytes + * @reason_size: Number of bytes valid for `reason` + * @reason: See Gunyah documentation for interpretation. Note: these values are + * not interpreted by Linux and need to be converted from little-endian + * as applicable. + */ +struct gunyah_vm_exit_info { + __u16 type; + __u16 padding; + __u32 reason_size; + __u8 reason[GUNYAH_VM_MAX_EXIT_REASON_SIZE]; +}; + +/** + * enum gunyah_vcpu_exit - Stores reason why &GUNYAH_VCPU_RUN ioctl recently exited with status 0 + * @GUNYAH_VCPU_EXIT_UNKNOWN: Not used, status != 0 + * @GUNYAH_VCPU_EXIT_MMIO: vCPU performed a read or write that could not be handled + * by hypervisor or Linux. Use @struct gunyah_vcpu_run.mmio for + * details of the read/write. + * @GUNYAH_VCPU_EXIT_STATUS: vCPU not able to run because the VM has exited. + * Use @struct gunyah_vcpu_run.status for why VM has exited. + * @GUNYAH_VCPU_EXIT_PAGE_FAULT: vCPU tried to execute an instruction at an address + * for which memory hasn't been provided. Use + * @struct gunyah_vcpu_run.page_fault for details. + */ +enum gunyah_vcpu_exit { + GUNYAH_VCPU_EXIT_UNKNOWN, + GUNYAH_VCPU_EXIT_MMIO, + GUNYAH_VCPU_EXIT_STATUS, + GUNYAH_VCPU_EXIT_PAGE_FAULT, +}; + +/** + * enum gunyah_vcpu_resume_action - Provide resume action after an MMIO or page fault + * @GUNYAH_VCPU_RESUME_HANDLED: The mmio or page fault has been handled, continue + * normal operation of vCPU + * @GUNYAH_VCPU_RESUME_FAULT: The mmio or page fault could not be satisfied and + * inject the original fault back to the guest. + * @GUNYAH_VCPU_RESUME_RETRY: Retry the faulting instruction. Perhaps you added + * memory binding to satisfy the request. + */ +enum gunyah_vcpu_resume_action { + GUNYAH_VCPU_RESUME_HANDLED = 0, + GUNYAH_VCPU_RESUME_FAULT, + GUNYAH_VCPU_RESUME_RETRY, +}; + +/** + * struct gunyah_vcpu_run - Application code obtains a pointer to the gunyah_vcpu_run + * structure by mmap()ing a vcpu fd. + * @immediate_exit: polled when scheduling the vcpu. If set, immediately returns -EINTR. + * @padding: padding bytes + * @exit_reason: Set when GUNYAH_VCPU_RUN returns successfully and gives reason why + * GUNYAH_VCPU_RUN has stopped running the vCPU. See &enum gunyah_vcpu_exit. + * @mmio: Used when exit_reason == GUNYAH_VCPU_EXIT_MMIO + * The guest has faulted on an memory-mapped I/O that + * couldn't be satisfied by gunyah. + * @mmio.phys_addr: Address guest tried to access + * @mmio.data: the value that was written if `is_write == 1`. Filled by + * user for reads (`is_write == 0`). + * @mmio.len: Length of write. Only the first `len` bytes of `data` + * are considered by Gunyah. + * @mmio.is_write: 1 if VM tried to perform a write, 0 for a read + * @mmio.resume_action: See &enum gunyah_vcpu_resume_action + * @status: Used when exit_reason == GUNYAH_VCPU_EXIT_STATUS. + * The guest VM is no longer runnable. This struct informs why. + * @status.status: See &enum gunyah_vm_status for possible values + * @status.exit_info: Used when status == GUNYAH_VM_STATUS_EXITED + * @page_fault: Used when EXIT_REASON == GUNYAH_VCPU_EXIT_PAGE_FAULT + * The guest has faulted on a region that can only be provided + * by mapping memory at phys_addr. + * @page_fault.phys_addr: Address guest tried to access. + * @page_fault.attempt: Error code why Linux wasn't able to handle fault itself + * Typically, if no memory was mapped: -ENOENT, + * If permission bits weren't what the VM wanted: -EPERM + * @page_fault.resume_action: See &enum gunyah_vcpu_resume_action + */ +struct gunyah_vcpu_run { + /* in */ + __u8 immediate_exit; + __u8 padding[7]; + + /* out */ + __u32 exit_reason; + + union { + struct { + __u64 phys_addr; + __u8 data[8]; + __u32 len; + __u8 is_write; + __u8 resume_action; + } mmio; + + struct { + enum gunyah_vm_status status; + struct gunyah_vm_exit_info exit_info; + } status; + + struct { + __u64 phys_addr; + __s32 attempt; + __u8 resume_action; + } page_fault; + }; +}; + +#define GUNYAH_VCPU_RUN _IO(GUNYAH_IOCTL_TYPE, 0x5) +#define GUNYAH_VCPU_MMAP_SIZE _IO(GUNYAH_IOCTL_TYPE, 0x6) + #endif From patchwork Thu Feb 22 23:16:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D075C54798 for ; Thu, 22 Feb 2024 23:17:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8418E6B009A; Thu, 22 Feb 2024 18:16:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 76E0C6B009F; Thu, 22 Feb 2024 18:16:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02D836B009D; Thu, 22 Feb 2024 18:16:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A1AB66B009C for ; Thu, 22 Feb 2024 18:16:48 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 67A74C0FB0 for ; Thu, 22 Feb 2024 23:16:48 +0000 (UTC) X-FDA: 81821001696.11.E67D421 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf11.hostedemail.com (Postfix) with ESMTP id 3492140012 for ; Thu, 22 Feb 2024 23:16:45 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=KBZZOdWE; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643806; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HSfYN4ASmajbR465rFcbd8dDlprgPpo+2HlUXq69zlQ=; b=rXIaUIl0zey+DMZAYTrzur0pJylTIYdZh8STCU3rSSg4lKVUH8qzMhJWu9ZomHTI8TJZZr lPH0fujvKbRyUbB4GhFcSssqk2PKCQeQALt0flmNiEGUcyAZYxXmY9Z/2rW8aNidu/gWn3 MdSAhkc8xCW5oACIqrEDkt8+i+8/DqU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=KBZZOdWE; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643806; a=rsa-sha256; cv=none; b=ceLfCDrDcQXpjtCrztmGqkJk8mEym7iwbJ/2/VVF80WVmUNp3G4YgkEaPkToovd6i0r3+R zCqIoKoyOU5z3sldbMA2Ryjp/MatBMvwmXfMc14d9hZL9szuOH8me0JKJfTiFnA29alnBk RbKJjFAwLN07hM/KwxRDbSAzY1ldQkE= Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMbD9R002908; Thu, 22 Feb 2024 23:16:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=HSfYN4ASmajbR465rFcbd8dDlprgPpo+2HlUXq69zlQ =; b=KBZZOdWEpYyIHHsdQVqr01IY7F8f8kShHAH6rwPxXFMleuTm65CON99rn5u Vr62MR3hyz8ommojpHx/P8xTqWGT7Sm/UepRpOVpDbG0QEjqGYqkWjk340i1tBMz fcxu35kcasBlTqRykW2QDzICNtERSN+IK4aXZE+7p2v6IzEk2ylzKTCp4UI9HB/I cXmayPouDScih+1r4AhIPB9K0xpMvwBHvOhaBpvB6rz8+U/rTY8S1TSPpjNlmjsL zGNJIsRGSb3TDoV/o5OBs23GzjFWWlAFEjvvUYIKfL+fWC9JiZtsHjHrVsISO9fG CUi8G1FAxwpeYdxOeVUa1W9pmww== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we1b0jxst-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:37 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGanv016004 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:36 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:35 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:39 -0800 Subject: [PATCH v17 16/35] gunyah: Add hypercalls for demand paging MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-16-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: zQIDYaV4Xlly6E59RQQafshiQ0DfVG7f X-Proofpoint-GUID: zQIDYaV4Xlly6E59RQQafshiQ0DfVG7f X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=527 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3492140012 X-Stat-Signature: u7xbebxowf5zjwzae6mgfworucyhbpt9 X-Rspam-User: X-HE-Tag: 1708643805-773846 X-HE-Meta: U2FsdGVkX1922KArp698UQdUNhOCGag/s9rJg5EcgbL9WzARIkheAWL0mZ7XXK/ZdZACLE4mHPKhc5rpnVz2GhaKBjPhf1zcaTe7KCuK7XM42k+lQapBhe0zt7km2EdlSpg8XvR8PxZbDbSnqGYPoqYNjRfyiAMPM3oJyqjXxcannfK2Yj0GNDFQFvld+M27XB7PWFOzGlNLjcobxKlQhOSCpi3ZNM4rZnXyfP3eeES9fZOCxm3m17khZKiLScs8gTJ0D1SQKfULYfznp5FokuGpzxlpPNRSiuIPaylwO46IEWM4m6kK/iSHu4UJsk+J+QxdYS2rHxdxoOlNfJObG5opp2Ri2daK6L2hQ7qUvTfYVgh3BDngvDHzftNqcgSc0c0YYdEkyFjnFof2PhyQ259/nMLVYWQoMbQP5F3bS7VuaJpRXUhTuDVnwGfQSDmymdRamFm/lsTwCy1GMYZFGFrlCL9Wjq99YFFRw2iX+TRCb2WlCaVcYHmyeCXnCcKszRU+5IPEIfMO6pgo9xgonar6mM3+zIQglcDPq9BQJ7uj+UUCpwpFhCwn4uBrYOnEGB7jcbBqFHzwD+l7rXop+gmRHmC1ThQaoUaPJv4BKBWFFh+hTwKyE8ZX1TvV/FNO9ZXAvquweoxbukjsJJ+q6Ipelq2ezNUf6QaJLR6e4t+kAyRrl3/HqDPvp0rH4IgVkKPhhiZt1Ep5o8ZDa/m5LgO+n8yFxehznmRcqqphMg2UD8KjwSVvV9FiQNXIhTJ2Gv8u4FAZq1gk7eiYT7fuSXq8ag5Nbk1LlW+muSI1f6xQKxLVLdiqkGPnHQsD7sF7MKdXd67dyixs9WxegG9LJwlUrTRfR8xMhB+PX6exbTw9hVeBHkc4rk8mbvWs34AZQ/oHj6/7zZj2rbjaSkqudX0/A7tTx2vNVT6ZF51pZrwgLWjRpEHV1rnC0fRmzf65IGVOHbQLrw64Wu/XN8y RM/Mxjxw wPIxnDOwsLOXGe03QlXQKSHjCsvxkfK45W1wi6RGOUgO8uX9oVkpqoVlCuXYn/ikxYN6R+HDtU9g9MAZXIJZe4AnTdiNk5kwq25qJzq8R3VA46MZS0dK9uQmeyok/YM51vgsYZnJ8gcrUN8at5Py94egi2jW5i9FJZ4zjHgT0j7I4D62TopU2F6487qpJ0H/Sj9SuVi/ic+QUHFqeRjytFxjZ6iYwpLWKudCfYHJ62shQJImKJ62tQ5hlRxSP5O41oyVpf0n6Nc5lB7KCbddjZ1EM/XQoBmPh6DazZrN40zfMrJ9Kn3YLGKZCy3IXS71EgvBgoW6WZnM7YI5Lcvt5GJQXtXIv0iBr/mVXqUNjNUkoAPIEGeDL49AguAD9+AhAAkOb X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Three hypercalls are needed to support demand paging. In create page mappings for a virtual machine's address space, memory must be moved to a memory extent that is allowed to be mapped into that address space. Memory extents are Gunyah's implementation of access control. Once the memory is moved to the proper memory extent, the memory can be mapped into the VM's address space. Implement the bindings to perform those hypercalls. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- arch/arm64/gunyah/gunyah_hypercall.c | 87 ++++++++++++++++++++++++++++++++++++ arch/arm64/include/asm/gunyah.h | 21 +++++++++ include/linux/gunyah.h | 56 +++++++++++++++++++++++ 3 files changed, 164 insertions(+) diff --git a/arch/arm64/gunyah/gunyah_hypercall.c b/arch/arm64/gunyah/gunyah_hypercall.c index fee21df42c176..38403dc28c66f 100644 --- a/arch/arm64/gunyah/gunyah_hypercall.c +++ b/arch/arm64/gunyah/gunyah_hypercall.c @@ -39,6 +39,9 @@ EXPORT_SYMBOL_GPL(arch_is_gunyah_guest); #define GUNYAH_HYPERCALL_HYP_IDENTIFY GUNYAH_HYPERCALL(0x8000) #define GUNYAH_HYPERCALL_MSGQ_SEND GUNYAH_HYPERCALL(0x801B) #define GUNYAH_HYPERCALL_MSGQ_RECV GUNYAH_HYPERCALL(0x801C) +#define GUNYAH_HYPERCALL_ADDRSPACE_MAP GUNYAH_HYPERCALL(0x802B) +#define GUNYAH_HYPERCALL_ADDRSPACE_UNMAP GUNYAH_HYPERCALL(0x802C) +#define GUNYAH_HYPERCALL_MEMEXTENT_DONATE GUNYAH_HYPERCALL(0x8061) #define GUNYAH_HYPERCALL_VCPU_RUN GUNYAH_HYPERCALL(0x8065) /* clang-format on */ @@ -114,6 +117,90 @@ enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size, } EXPORT_SYMBOL_GPL(gunyah_hypercall_msgq_recv); +/** + * gunyah_hypercall_addrspace_map() - Add memory to an address space from a memory extent + * @capid: Address space capability ID + * @extent_capid: Memory extent capability ID + * @vbase: location in address space + * @extent_attrs: Attributes for the memory + * @flags: Flags for address space mapping + * @offset: Offset into memory extent (physical address of memory) + * @size: Size of memory to map; must be page-aligned + */ +enum gunyah_error gunyah_hypercall_addrspace_map(u64 capid, u64 extent_capid, u64 vbase, + u32 extent_attrs, u32 flags, u64 offset, u64 size) +{ + struct arm_smccc_1_2_regs args = { + .a0 = GUNYAH_HYPERCALL_ADDRSPACE_MAP, + .a1 = capid, + .a2 = extent_capid, + .a3 = vbase, + .a4 = extent_attrs, + .a5 = flags, + .a6 = offset, + .a7 = size, + /* C language says this will be implictly zero. Gunyah requires 0, so be explicit */ + .a8 = 0, + }; + struct arm_smccc_1_2_regs res; + + arm_smccc_1_2_hvc(&args, &res); + + return res.a0; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_addrspace_map); + +/** + * gunyah_hypercall_addrspace_unmap() - Remove memory from an address space + * @capid: Address space capability ID + * @extent_capid: Memory extent capability ID + * @vbase: location in address space + * @flags: Flags for address space mapping + * @offset: Offset into memory extent (physical address of memory) + * @size: Size of memory to map; must be page-aligned + */ +enum gunyah_error gunyah_hypercall_addrspace_unmap(u64 capid, u64 extent_capid, u64 vbase, + u32 flags, u64 offset, u64 size) +{ + struct arm_smccc_1_2_regs args = { + .a0 = GUNYAH_HYPERCALL_ADDRSPACE_UNMAP, + .a1 = capid, + .a2 = extent_capid, + .a3 = vbase, + .a4 = flags, + .a5 = offset, + .a6 = size, + /* C language says this will be implictly zero. Gunyah requires 0, so be explicit */ + .a7 = 0, + }; + struct arm_smccc_1_2_regs res; + + arm_smccc_1_2_hvc(&args, &res); + + return res.a0; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_addrspace_unmap); + +/** + * gunyah_hypercall_memextent_donate() - Donate memory from one memory extent to another + * @options: donate options + * @from_capid: Memory extent capability ID to donate from + * @to_capid: Memory extent capability ID to donate to + * @offset: Offset into memory extent (physical address of memory) + * @size: Size of memory to donate; must be page-aligned + */ +enum gunyah_error gunyah_hypercall_memextent_donate(u32 options, u64 from_capid, u64 to_capid, + u64 offset, u64 size) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GUNYAH_HYPERCALL_MEMEXTENT_DONATE, options, from_capid, to_capid, + offset, size, 0, &res); + + return res.a0; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_memextent_donate); + /** * gunyah_hypercall_vcpu_run() - Donate CPU time to a vcpu * @capid: capability ID of the vCPU to run diff --git a/arch/arm64/include/asm/gunyah.h b/arch/arm64/include/asm/gunyah.h index 0cd3debe22b64..4adf24977fd18 100644 --- a/arch/arm64/include/asm/gunyah.h +++ b/arch/arm64/include/asm/gunyah.h @@ -33,4 +33,25 @@ static inline int arch_gunyah_fill_irq_fwspec_params(u32 virq, return 0; } +enum arch_gunyah_memtype { + /* clang-format off */ + GUNYAH_MEMTYPE_DEVICE_nGnRnE = 0, + GUNYAH_DEVICE_nGnRE = 1, + GUNYAH_DEVICE_nGRE = 2, + GUNYAH_DEVICE_GRE = 3, + + GUNYAH_NORMAL_NC = 0b0101, + GUNYAH_NORMAL_ONC_IWT = 0b0110, + GUNYAH_NORMAL_ONC_IWB = 0b0111, + GUNYAH_NORMAL_OWT_INC = 0b1001, + GUNYAH_NORMAL_WT = 0b1010, + GUNYAH_NORMAL_OWT_IWB = 0b1011, + GUNYAH_NORMAL_OWB_INC = 0b1101, + GUNYAH_NORMAL_OWB_IWT = 0b1110, + GUNYAH_NORMAL_WB = 0b1111, + /* clang-format on */ +}; + +#define ARCH_GUNYAH_DEFAULT_MEMTYPE GUNYAH_NORMAL_WB + #endif diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 6c24544f38dc9..24c02c6827738 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -273,6 +273,62 @@ enum gunyah_error gunyah_hypercall_msgq_send(u64 capid, size_t size, void *buff, enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size, size_t *recv_size, bool *ready); +#define GUNYAH_ADDRSPACE_SELF_CAP 0 + +enum gunyah_pagetable_access { + /* clang-format off */ + GUNYAH_PAGETABLE_ACCESS_NONE = 0, + GUNYAH_PAGETABLE_ACCESS_X = 1, + GUNYAH_PAGETABLE_ACCESS_W = 2, + GUNYAH_PAGETABLE_ACCESS_R = 4, + GUNYAH_PAGETABLE_ACCESS_RX = 5, + GUNYAH_PAGETABLE_ACCESS_RW = 6, + GUNYAH_PAGETABLE_ACCESS_RWX = 7, + /* clang-format on */ +}; + +/* clang-format off */ +#define GUNYAH_MEMEXTENT_MAPPING_USER_ACCESS GENMASK_ULL(2, 0) +#define GUNYAH_MEMEXTENT_MAPPING_KERNEL_ACCESS GENMASK_ULL(6, 4) +#define GUNYAH_MEMEXTENT_MAPPING_TYPE GENMASK_ULL(23, 16) +/* clang-format on */ + +enum gunyah_memextent_donate_type { + /* clang-format off */ + GUNYAH_MEMEXTENT_DONATE_TO_CHILD = 0, + GUNYAH_MEMEXTENT_DONATE_TO_PARENT = 1, + GUNYAH_MEMEXTENT_DONATE_TO_SIBLING = 2, + GUNYAH_MEMEXTENT_DONATE_TO_PROTECTED = 3, + GUNYAH_MEMEXTENT_DONATE_FROM_PROTECTED = 4, + /* clang-format on */ +}; + +enum gunyah_addrspace_map_flag_bits { + /* clang-format off */ + GUNYAH_ADDRSPACE_MAP_FLAG_PARTIAL = 0, + GUNYAH_ADDRSPACE_MAP_FLAG_PRIVATE = 1, + GUNYAH_ADDRSPACE_MAP_FLAG_VMMIO = 2, + GUNYAH_ADDRSPACE_MAP_FLAG_NOSYNC = 31, + /* clang-format on */ +}; + +enum gunyah_error gunyah_hypercall_addrspace_map(u64 capid, u64 extent_capid, + u64 vbase, u32 extent_attrs, + u32 flags, u64 offset, + u64 size); +enum gunyah_error gunyah_hypercall_addrspace_unmap(u64 capid, u64 extent_capid, + u64 vbase, u32 flags, + u64 offset, u64 size); + +/* clang-format off */ +#define GUNYAH_MEMEXTENT_OPTION_TYPE_MASK GENMASK_ULL(7, 0) +#define GUNYAH_MEMEXTENT_OPTION_NOSYNC BIT(31) +/* clang-format on */ + +enum gunyah_error gunyah_hypercall_memextent_donate(u32 options, u64 from_capid, + u64 to_capid, u64 offset, + u64 size); + struct gunyah_hypercall_vcpu_run_resp { union { enum { From patchwork Thu Feb 22 23:16:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568238 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F9D5C54798 for ; Thu, 22 Feb 2024 23:17:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 586B86B009B; Thu, 22 Feb 2024 18:16:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EBFA6B009A; Thu, 22 Feb 2024 18:16:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E36136B009E; Thu, 22 Feb 2024 18:16:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 99DB86B009B for ; Thu, 22 Feb 2024 18:16:48 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7D21B1A0FCC for ; Thu, 22 Feb 2024 23:16:48 +0000 (UTC) X-FDA: 81821001696.08.8082F20 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf30.hostedemail.com (Postfix) with ESMTP id 76AAB80005 for ; Thu, 22 Feb 2024 23:16:46 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=kUkiyRoZ; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf30.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643806; a=rsa-sha256; cv=none; b=iCULHijYC5+9XNB57YLUbnEvMpxwr8SwyvJdBwcQdd2I4pZyADPdXK2IxGclDTOlVOkyRI nnW8RUPuzkOBVZhjPMYjpNnYzjU5E09uJ1Ghiw6R8qKmlCjx4l0xnejjyshnwCLuf/fdtx oc3WK+lkMlI0agJznsyVK8CvvPX4Fpg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=kUkiyRoZ; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf30.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643806; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QOElK17u6E3Oi3fGlR8GhCpi5hNeTK7D9iwXe+8Bw34=; b=IRbBkKjtSsRuHvebH7QPnJ0vef/uhNazKfCneYZsSXTxANKiqLfoe13yK43aeAjMV0VG5S uTghJshGUj51gLDj6J++E0Ga8otaUOlF7a87vi212w7/hZh3ul4t4eiI3fd2Lifw4sssO0 ypo1HQqHpvXe5ez3sGB4HV8WqVTd9Do= Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MNGdjl001674; Thu, 22 Feb 2024 23:16:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=QOElK17u6E3Oi3fGlR8GhCpi5hNeTK7D9iwXe+8Bw34 =; b=kUkiyRoZhpF+VhFYXyKNehELIsxXKqQCNGVKq5dSo95gXwCKF2H6s7E7UTy 12NpgIhKGjAlx+iWBLt99VN///DT7upTtJduE8Lxd71EfkZEGBan9FSLrNdlIwCg zmQ/8XUX2PCCLF5q4fDjXrYk3zi9OyEDO4+Legf7jtdOXU8bmnagEMkgxcRwj+Og LUqUdFP8XCldyW0ozp7TCQ7b7kaVxpbzhhb9tiEsLhK3Vass9cEiX/X2qdtzuuhO OWPq3vaw4uVbt4hbMR/yC32VG7bC2FTdPl6daTDLox3CcKRonhFY+Y76NQ4kmo8T swor0lkxK/jbbzH73aqiPpEyP7Q== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we3231h1q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:38 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGb3g027723 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:37 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:36 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:40 -0800 Subject: [PATCH v17 17/35] gunyah: rsc_mgr: Add memory parcel RPC MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-17-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: gDskPpvfFJmKBC3FrTuBVwtnBo_nzmIY X-Proofpoint-GUID: gDskPpvfFJmKBC3FrTuBVwtnBo_nzmIY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 clxscore=1015 suspectscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220178 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 76AAB80005 X-Stat-Signature: 4jupukz5i65z8cm977onnp99jzywszjr X-HE-Tag: 1708643806-982882 X-HE-Meta: U2FsdGVkX18j9BFcNy2HVd9YOO9YCHFfqw2JS6/f3MQdm49iLi3TUBMATWEITCPLCxUayyGkGSgz0xeoI2bxlpEk/CBx4k4uPlYZEvyb3X/LH1LBJFxQzN3VyVcyQf8HjfBOPl7snhzlFPJlFKgHJ9GqbH+JZtvHJ36Ufrifblo2rdW1b2g272DgUROSnwKGCNsjJIQbJR3fT2f/C3rnsBwrpjQeFJiw1P1c1on31YFgG40meAtP+bj5StU0HGubtm8C6155VUQ11UAoT7WxvU3mDXP1UkFotRZp0ZkJdmCKM7av6GEKcRHFSl6y+PTkZlIYznBVtDqyvBfcRKaDC01aPbG0h5smlws5DNqHHIUVRRZ+x6ByfgQfaH1bMka5ckoTERfr4MLsEJeSD4eC9LhcMlVv7vg4g8ZIuNuwykTsBojYQcS+jc5Jq2fIRNQ8REA016V9dVb7HxR7lXPDArfthEMl+XCwvoyQMY5ZV/GGXSY/hts60JSQX2LcF2pR6VvRNbQSPHOSH0X+9n7Bz2GJwKb1dlZjb1EOznqsmbij2nsf5CkXhZMgeZPsOdgSstHiaQOqGC+ycnbwC75PL2Pna176FfWC4FW39fzaG9k3f0f6r+xKWnEfMZsAe5YLi0CyYxnLrJPNCdfgYvt0XVDBIjHatCxA/AQqcFod1juvBUIWD3YVHzTHGxdVF0fL0DbnLuFxgyQIPym0YVuN9dd+ZC6VfngXCQEwhxEKto/ExNn9I/CH0jJsBIxzV6nk90+nK0QIrnpJvTKgnLKNsHMe1BdayUy6y+l33DlRWOg4eG7l0AX0HyPDZbILsqgS8x9pFaT+CVoPEw86caWLse7ygIH4JVnUmqyKy00r6AdMHUKiI3vRxMgcEkYwGwZzqE7nX6AoIs4PLzNcQhglZmhR8oKgiVYNJ+6rutN/9+BlpmZC9S9qWmMEVbXlOUhIpLr/ArHgP7cdzh4jNAR r8rnGgB6 OaSlMkgcXxsJtd758d4UDfhlnGoSZ6h7C/nGN X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In a Gunyah hypervisor system using the Gunyah Resource Manager, the "standard" unit of donating, lending and sharing memory is called a memory parcel (memparcel). A memparcel is an abstraction used by the resource manager for securely managing donating, lending and sharing memory, which may be physically and virtually fragmented, without dealing directly with physical memory addresses. Memparcels are created and managed through the RM RPC functions for lending, sharing and reclaiming memory from VMs. When creating a new VM the initial VM memory containing the VM image and the VM's device tree blob must be provided as a memparcel. The memparcel must be created using the RM RPC for lending and mapping the memory to the VM. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- drivers/virt/gunyah/rsc_mgr.h | 9 ++ drivers/virt/gunyah/rsc_mgr_rpc.c | 234 ++++++++++++++++++++++++++++++++++++++ include/linux/gunyah.h | 43 +++++++ 3 files changed, 286 insertions(+) diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index 52711de77bb79..ec8ad8149e8ef 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -10,6 +10,7 @@ #include #define GUNYAH_VMID_INVAL U16_MAX +#define GUNYAH_MEM_HANDLE_INVAL U32_MAX struct gunyah_rm; @@ -58,6 +59,12 @@ struct gunyah_rm_vm_status_payload { __le16 app_status; } __packed; +/* RPC Calls */ +int gunyah_rm_mem_share(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *parcel); +int gunyah_rm_mem_reclaim(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *parcel); + int gunyah_rm_alloc_vmid(struct gunyah_rm *rm, u16 vmid); int gunyah_rm_dealloc_vmid(struct gunyah_rm *rm, u16 vmid); int gunyah_rm_vm_reset(struct gunyah_rm *rm, u16 vmid); @@ -99,6 +106,8 @@ struct gunyah_rm_hyp_resources { int gunyah_rm_get_hyp_resources(struct gunyah_rm *rm, u16 vmid, struct gunyah_rm_hyp_resources **resources); +int gunyah_rm_get_vmid(struct gunyah_rm *rm, u16 *vmid); + struct gunyah_resource * gunyah_rm_alloc_resource(struct gunyah_rm *rm, struct gunyah_rm_hyp_resource *hyp_resource); diff --git a/drivers/virt/gunyah/rsc_mgr_rpc.c b/drivers/virt/gunyah/rsc_mgr_rpc.c index c2f4ccae8f3bc..eb06940bb3c53 100644 --- a/drivers/virt/gunyah/rsc_mgr_rpc.c +++ b/drivers/virt/gunyah/rsc_mgr_rpc.c @@ -7,6 +7,12 @@ #include "rsc_mgr.h" +/* Message IDs: Memory Management */ +#define GUNYAH_RM_RPC_MEM_LEND 0x51000012 +#define GUNYAH_RM_RPC_MEM_SHARE 0x51000013 +#define GUNYAH_RM_RPC_MEM_RECLAIM 0x51000015 +#define GUNYAH_RM_RPC_MEM_APPEND 0x51000018 + /* Message IDs: VM Management */ /* clang-format off */ #define GUNYAH_RM_RPC_VM_ALLOC_VMID 0x56000001 @@ -17,6 +23,7 @@ #define GUNYAH_RM_RPC_VM_CONFIG_IMAGE 0x56000009 #define GUNYAH_RM_RPC_VM_INIT 0x5600000B #define GUNYAH_RM_RPC_VM_GET_HYP_RESOURCES 0x56000020 +#define GUNYAH_RM_RPC_VM_GET_VMID 0x56000024 /* clang-format on */ struct gunyah_rm_vm_common_vmid_req { @@ -24,6 +31,49 @@ struct gunyah_rm_vm_common_vmid_req { __le16 _padding; } __packed; +/* Call: MEM_LEND, MEM_SHARE */ +#define GUNYAH_RM_MAX_MEM_ENTRIES 512 + +#define GUNYAH_MEM_SHARE_REQ_FLAGS_APPEND BIT(1) + +struct gunyah_rm_mem_share_req_header { + u8 mem_type; + u8 _padding0; + u8 flags; + u8 _padding1; + __le32 label; +} __packed; + +struct gunyah_rm_mem_share_req_acl_section { + __le16 n_entries; + __le16 _padding; + struct gunyah_rm_mem_acl_entry entries[]; +} __packed; + +struct gunyah_rm_mem_share_req_mem_section { + __le16 n_entries; + __le16 _padding; + struct gunyah_rm_mem_entry entries[]; +} __packed; + +/* Call: MEM_RELEASE */ +struct gunyah_rm_mem_release_req { + __le32 mem_handle; + u8 flags; /* currently not used */ + u8 _padding0; + __le16 _padding1; +} __packed; + +/* Call: MEM_APPEND */ +#define GUNYAH_MEM_APPEND_REQ_FLAGS_END BIT(0) + +struct gunyah_rm_mem_append_req_header { + __le32 mem_handle; + u8 flags; + u8 _padding0; + __le16 _padding1; +} __packed; + /* Call: VM_ALLOC */ struct gunyah_rm_vm_alloc_vmid_resp { __le16 vmid; @@ -68,6 +118,161 @@ static int gunyah_rm_common_vmid_call(struct gunyah_rm *rm, u32 message_id, NULL, NULL); } +static int gunyah_rm_mem_append(struct gunyah_rm *rm, u32 mem_handle, + struct gunyah_rm_mem_entry *entries, + size_t n_entries) +{ + struct gunyah_rm_mem_append_req_header *req __free(kfree) = NULL; + struct gunyah_rm_mem_share_req_mem_section *mem; + int ret = 0; + size_t n; + + req = kzalloc(sizeof(*req) + struct_size(mem, entries, GUNYAH_RM_MAX_MEM_ENTRIES), + GFP_KERNEL); + if (!req) + return -ENOMEM; + + req->mem_handle = cpu_to_le32(mem_handle); + mem = (void *)(req + 1); + + while (n_entries) { + req->flags = 0; + if (n_entries > GUNYAH_RM_MAX_MEM_ENTRIES) { + n = GUNYAH_RM_MAX_MEM_ENTRIES; + } else { + req->flags |= GUNYAH_MEM_APPEND_REQ_FLAGS_END; + n = n_entries; + } + + mem->n_entries = cpu_to_le16(n); + memcpy(mem->entries, entries, sizeof(*entries) * n); + + ret = gunyah_rm_call(rm, GUNYAH_RM_RPC_MEM_APPEND, req, + sizeof(*req) + struct_size(mem, entries, n), + NULL, NULL); + if (ret) + break; + + entries += n; + n_entries -= n; + } + + return ret; +} + +/** + * gunyah_rm_mem_share() - Share memory with other virtual machines. + * @rm: Handle to a Gunyah resource manager + * @p: Information about the memory to be shared. + * + * Sharing keeps Linux's access to the memory while the memory parcel is shared. + */ +int gunyah_rm_mem_share(struct gunyah_rm *rm, struct gunyah_rm_mem_parcel *p) +{ + u32 message_id = p->n_acl_entries == 1 ? GUNYAH_RM_RPC_MEM_LEND : + GUNYAH_RM_RPC_MEM_SHARE; + size_t msg_size, initial_mem_entries = p->n_mem_entries, resp_size; + struct gunyah_rm_mem_share_req_acl_section *acl; + struct gunyah_rm_mem_share_req_mem_section *mem; + struct gunyah_rm_mem_share_req_header *req_header; + size_t acl_size, mem_size; + u32 *attr_section; + bool need_append = false; + __le32 *resp; + void *msg; + int ret; + + if (!p->acl_entries || !p->n_acl_entries || !p->mem_entries || + !p->n_mem_entries || p->n_acl_entries > U8_MAX || + p->mem_handle != GUNYAH_MEM_HANDLE_INVAL) + return -EINVAL; + + if (initial_mem_entries > GUNYAH_RM_MAX_MEM_ENTRIES) { + initial_mem_entries = GUNYAH_RM_MAX_MEM_ENTRIES; + need_append = true; + } + + acl_size = struct_size(acl, entries, p->n_acl_entries); + mem_size = struct_size(mem, entries, initial_mem_entries); + + /* The format of the message goes: + * request header + * ACL entries (which VMs get what kind of access to this memory parcel) + * Memory entries (list of memory regions to share) + * Memory attributes (currently unused, we'll hard-code the size to 0) + */ + msg_size = sizeof(struct gunyah_rm_mem_share_req_header) + acl_size + + mem_size + + sizeof(u32); /* for memory attributes, currently unused */ + + msg = kzalloc(msg_size, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + req_header = msg; + acl = (void *)req_header + sizeof(*req_header); + mem = (void *)acl + acl_size; + attr_section = (void *)mem + mem_size; + + req_header->mem_type = p->mem_type; + if (need_append) + req_header->flags |= GUNYAH_MEM_SHARE_REQ_FLAGS_APPEND; + req_header->label = cpu_to_le32(p->label); + + acl->n_entries = cpu_to_le32(p->n_acl_entries); + memcpy(acl->entries, p->acl_entries, + flex_array_size(acl, entries, p->n_acl_entries)); + + mem->n_entries = cpu_to_le16(initial_mem_entries); + memcpy(mem->entries, p->mem_entries, + flex_array_size(mem, entries, initial_mem_entries)); + + /* Set n_entries for memory attribute section to 0 */ + *attr_section = 0; + + ret = gunyah_rm_call(rm, message_id, msg, msg_size, (void **)&resp, + &resp_size); + kfree(msg); + + if (ret) + return ret; + + p->mem_handle = le32_to_cpu(*resp); + kfree(resp); + + if (need_append) { + ret = gunyah_rm_mem_append( + rm, p->mem_handle, &p->mem_entries[initial_mem_entries], + p->n_mem_entries - initial_mem_entries); + if (ret) { + gunyah_rm_mem_reclaim(rm, p); + p->mem_handle = GUNYAH_MEM_HANDLE_INVAL; + } + } + + return ret; +} +ALLOW_ERROR_INJECTION(gunyah_rm_mem_share, ERRNO); + +/** + * gunyah_rm_mem_reclaim() - Reclaim a memory parcel + * @rm: Handle to a Gunyah resource manager + * @parcel: Information about the memory to be reclaimed. + * + * RM maps the associated memory back into the stage-2 page tables of the owner VM. + */ +int gunyah_rm_mem_reclaim(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *parcel) +{ + struct gunyah_rm_mem_release_req req = { + .mem_handle = cpu_to_le32(parcel->mem_handle), + }; + + return gunyah_rm_call(rm, GUNYAH_RM_RPC_MEM_RECLAIM, &req, sizeof(req), + NULL, NULL); +} +ALLOW_ERROR_INJECTION(gunyah_rm_mem_reclaim, ERRNO); + /** * gunyah_rm_alloc_vmid() - Allocate a new VM in Gunyah. Returns the VM identifier. * @rm: Handle to a Gunyah resource manager @@ -246,3 +451,32 @@ int gunyah_rm_get_hyp_resources(struct gunyah_rm *rm, u16 vmid, return 0; } ALLOW_ERROR_INJECTION(gunyah_rm_get_hyp_resources, ERRNO); + +/** + * gunyah_rm_get_vmid() - Retrieve VMID of this virtual machine + * @rm: Handle to a Gunyah resource manager + * @vmid: Filled with the VMID of this VM + */ +int gunyah_rm_get_vmid(struct gunyah_rm *rm, u16 *vmid) +{ + static u16 cached_vmid = GUNYAH_VMID_INVAL; + size_t resp_size; + __le32 *resp; + int ret; + + if (cached_vmid != GUNYAH_VMID_INVAL) { + *vmid = cached_vmid; + return 0; + } + + ret = gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_GET_VMID, NULL, 0, + (void **)&resp, &resp_size); + if (ret) + return ret; + + *vmid = cached_vmid = lower_16_bits(le32_to_cpu(*resp)); + kfree(resp); + + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_rm_get_vmid); diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 24c02c6827738..c23e1a88703e8 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -155,6 +155,49 @@ int gunyah_vm_add_resource_ticket(struct gunyah_vm *ghvm, void gunyah_vm_remove_resource_ticket(struct gunyah_vm *ghvm, struct gunyah_vm_resource_ticket *ticket); +#define GUNYAH_RM_ACL_X BIT(0) +#define GUNYAH_RM_ACL_W BIT(1) +#define GUNYAH_RM_ACL_R BIT(2) + +struct gunyah_rm_mem_acl_entry { + __le16 vmid; + u8 perms; + u8 reserved; +} __packed; + +struct gunyah_rm_mem_entry { + __le64 phys_addr; + __le64 size; +} __packed; + +enum gunyah_rm_mem_type { + GUNYAH_RM_MEM_TYPE_NORMAL = 0, + GUNYAH_RM_MEM_TYPE_IO = 1, +}; + +/* + * struct gunyah_rm_mem_parcel - Info about memory to be lent/shared/donated/reclaimed + * @mem_type: The type of memory: normal (DDR) or IO + * @label: An client-specified identifier which can be used by the other VMs to identify the purpose + * of the memory parcel. + * @n_acl_entries: Count of the number of entries in the @acl_entries array. + * @acl_entries: An array of access control entries. Each entry specifies a VM and what access + * is allowed for the memory parcel. + * @n_mem_entries: Count of the number of entries in the @mem_entries array. + * @mem_entries: An array of regions to be associated with the memory parcel. Addresses should be + * (intermediate) physical addresses from Linux's perspective. + * @mem_handle: On success, filled with memory handle that RM allocates for this memory parcel + */ +struct gunyah_rm_mem_parcel { + enum gunyah_rm_mem_type mem_type; + u32 label; + size_t n_acl_entries; + struct gunyah_rm_mem_acl_entry *acl_entries; + size_t n_mem_entries; + struct gunyah_rm_mem_entry *mem_entries; + u32 mem_handle; +}; + /******************************************************************************/ /* Common arch-independent definitions for Gunyah hypercalls */ #define GUNYAH_CAPID_INVAL U64_MAX From patchwork Thu Feb 22 23:16:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568236 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ED48C54E49 for ; Thu, 22 Feb 2024 23:17:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 252E16B0098; Thu, 22 Feb 2024 18:16:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 201EC6B009A; Thu, 22 Feb 2024 18:16:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02FBE6B009B; Thu, 22 Feb 2024 18:16:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E047B6B0098 for ; Thu, 22 Feb 2024 18:16:47 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B4F38121039 for ; Thu, 22 Feb 2024 23:16:47 +0000 (UTC) X-FDA: 81821001654.13.3DFE4E9 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf14.hostedemail.com (Postfix) with ESMTP id 90011100010 for ; Thu, 22 Feb 2024 23:16:45 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=G8zLuS0q; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf14.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643805; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=a8k7ZP82tn4JVJwW+w/m7k4EoKpoY9RGrzHrrV6tQxc=; b=JX9Cemk+pkWRksgYWNGgBfBiR9jcUJJNpaFqQZb/C3KweVHqxmBgB5otPfzZPVzi9hFjCD 3+G2thlREuJ43gqC6ZS/9eoBh2vfQhVeYe+8BQt8UpGr9FkRjgL8bSGlUFpB7ZZJwrR54b GUUpGCSPKANFf5XtLtkQSH4qpYDSj3w= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=G8zLuS0q; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf14.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643805; a=rsa-sha256; cv=none; b=IuG8wmBClwYLGJO8ykPLDm9A/E58RGUIZeyu+33TLTrVFKEnBAQjt/9GXbKxXjRiuxXwnf CUIaVvDy+i6MtiweHszsKZ/Czd6rHyZ/AXobMg756hRJnqlvUWjP0gQI4fbOE/iS5d9G4n AiOsKelU9E/tR/zQyK4L7oAjy+GlkDI= Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MN1D1E020603; Thu, 22 Feb 2024 23:16:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=a8k7ZP82tn4JVJwW+w/m7k4EoKpoY9RGrzHrrV6tQxc =; b=G8zLuS0qr6d4lZUoE5CoDx+OQ1H30bu9JjA/DBQ4WHtPH6Y32oBCFeCUzqq aRECHJ8Nnre0wYkRag/a/bnHEq5di/ZfvzIFt40zo/It/7L/Yo3lf0a0UtEAs7pZ SbKN6b5H8bqSMLS9E5/YsoEbDzUgXoHRkwYC5+EJ2/mG09No+OQvpbVvPio+rs7L 4NoKBtTgW+NDPapXhOFi05jweADI/zkiqUBOSN6yH8dLtghTmF9WdFTRMy56NPQY Vv4A92LdxJ2FBQwkeDpNGUF12C3AqSq78fBdwbCBnGZY3F0qL4c9LQ2ISi/HfvhP Begi0gYT0HyrwE02SVJkWZOk9xw== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we4dq17sq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:38 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGbaG027727 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:37 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:37 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:41 -0800 Subject: [PATCH v17 18/35] mm/interval_tree: Export iter_first/iter_next MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-18-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: S-X8YH9UOQhwdKZl5qZ08gJqpUzKbDlZ X-Proofpoint-ORIG-GUID: S-X8YH9UOQhwdKZl5qZ08gJqpUzKbDlZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 adultscore=0 mlxlogscore=955 clxscore=1015 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 90011100010 X-Stat-Signature: 3z5rpc9w3atssqdfxm7kygkoqj78a4tp X-HE-Tag: 1708643805-656268 X-HE-Meta: U2FsdGVkX1+KGIevRD+l4etPW00o+8Tx1j07lepo/lv7H3T5Q76Sqpe1OcmQDma/WsRP/BLml6NK/HQUOkdweAeXr1Wmp9u8elFWawWPfc3acMIjsufShXv2JUOOkuZ2LW94dSUAi1Et3x5vDTo4C28kPwOueUYv7Y0O79HMHKFMHZaqAngCu0gLAKyJEIFSQZaCOU5TXu6n0TnANSOUQ6/ENSsbjBLdOZzp9unPYCWY+GcFJNtemjc/uRwfjvhzzJv6b+/6JOokrsbQ5jZlL6PXdOHWC8NFb1R3edtu1KodnmR5VLFFTVr8nTsS0mPLs+FqihTAj9i6R6RijKx4u/P4DHynW8j5iKo1/g2sYubKOustNJxKT8YKTmtBrUvzy6nmyElIoTlANSIKRkKAO1J5Z5p62SRBrIYRXAiVPeGFp9+5s84vaNR/v5caMv4cnwvp5UjCzzNSwjw322TJOs7bk0bBVnMLb+3/3c7WakJus3HBDatWNPhANPYWMIhTtJoLJdTCJwpt5a90BBoXkVJ7MDe8yP69WzWhYjiDEi43dGUx47FwOwPQntzmaSgxJLHTh+XjaCCk7PnCKP+aWApcMJGU5WYxHl4YOWoFOwRatGcnWmjyEljIZB+IAZflFHj3ln+S0Hd0FqkdB5C4P+K+FqdFgI2rZWaQ/ONUmOSqQkMPH9KAmVI5lZqiC7fxBUtqiX0hf1XDPLIKiC8lADHl068BsjOmkRnXZCAufD4rErofOY2XcXuAGcPX6qjlgOh6Sk1Sh6AtphmA3iPbVHDzcZAyj9z5EKXDevi8ykAKZtrd90JQSlZhqCBuQV77GA+HYbMteDGZwyYWtp7CFlrPcyYprKTCZKhX3DcChfYHorVdiCLBCzoDK9emFujoeGtq3hnjJ5QWXc0qV9IxLg1gRLhe7RUpxO2jyFq7NpQ6gX2pcZJBhCmqTv9FBJZy08NItG3+tnNZDnhMzd5 /xnIRX7y 2JlU9xbosAuO0i5J3CWnI400aIzDYAViSpzkiIJqCVWPtzAdUl7lEI8lsXe0x1XDTe9QhqMVSd7NoYWuug18zjGdQ672m1Gbo/JJM+Cs/jHeZAnUmO2nCpN5gJGwQNjFYQGUEWke3Ce4kZCd7AvwW4Qyf8W3p4riBYLSbwUFXMwpLqmu99+Cjz27yPAZmP8QOUCrqb2cWXQZ1u7meXSU2KCTDcgkICd1MzLjTEe9fRJQfNhc5eJuCuroSr9XSh00jj9k0//NQB0QIcgySAQgmqlbdL0OvY/0dtSLmR9xglyaYu5xk1IX1cbpciUfziYXb68XJu0T+JieSUIcY6raXhLj5qogWqElnfL/5r8+EHM56pr19ZrtsRp06IcMZ0RqgIq5TT8SOFz/H5h5ZErpY7YCmvDHJwQztJkVxR0rtntNStwA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Export vma_interval_tree_iter_first and vma_interval_tree_iter_next for vma_interval_tree_foreach. Signed-off-by: Elliot Berman --- mm/interval_tree.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/interval_tree.c b/mm/interval_tree.c index 32e390c42c53f..faa50767496c3 100644 --- a/mm/interval_tree.c +++ b/mm/interval_tree.c @@ -24,6 +24,9 @@ INTERVAL_TREE_DEFINE(struct vm_area_struct, shared.rb, unsigned long, shared.rb_subtree_last, vma_start_pgoff, vma_last_pgoff, /* empty */, vma_interval_tree) +EXPORT_SYMBOL_GPL(vma_interval_tree_iter_first); +EXPORT_SYMBOL_GPL(vma_interval_tree_iter_next); + /* Insert node immediately after prev in the interval tree */ void vma_interval_tree_insert_after(struct vm_area_struct *node, struct vm_area_struct *prev, From patchwork Thu Feb 22 23:16:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5C8AC47DD9 for ; Thu, 22 Feb 2024 23:17:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DE846B009C; Thu, 22 Feb 2024 18:16:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16A366B009B; Thu, 22 Feb 2024 18:16:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9C556B009F; Thu, 22 Feb 2024 18:16:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BF6456B009D for ; Thu, 22 Feb 2024 18:16:48 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 95E8CC1049 for ; Thu, 22 Feb 2024 23:16:48 +0000 (UTC) X-FDA: 81821001696.06.BAC2A5F Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf22.hostedemail.com (Postfix) with ESMTP id 88B22C0005 for ; Thu, 22 Feb 2024 23:16:46 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=Aex6mvf2; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf22.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643806; a=rsa-sha256; cv=none; b=f9xtDjVvpleURG3KbEKUTLTxkHaopEA0ZK4/FpQ4d368pBSvzB8UxZ28JdG0waY80DZIdT hv2kd1hkGCHqMXD0MApLS/mP9aUoUzCAc+jA1MpHHaEyMCIfhVOGlOawI4PojbxlyLqM77 hbvy9XXufbo5/9K7dT/Ij9bM5PC6e1c= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=Aex6mvf2; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf22.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643806; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BqFFNu68PPJsdW9psryeqdBWeZaEA8iJMtTYpGjEiRs=; b=NJHbZ28n10jmDFiK8nXUC3S+vAvfJqXiCGlH4furAxKovuLojoRr/U49EWtiz6DlgR5/50 4Q0qF9KYlZLevRYQP+EbTFRPWuS4zTb4mRSG7biEojRKS1JXq21snP2Ii5xLDJvmCJLYGq IjR5gTqflqQk6zCJ7giC7nHYvHZsX7A= Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLSSYf024471; Thu, 22 Feb 2024 23:16:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=BqFFNu68PPJsdW9psryeqdBWeZaEA8iJMtTYpGjEiRs =; b=Aex6mvf2g3FnivTElXrRrrHWoO98H3rwWvOrmltuggNv3WUhHob6R/Efvf5 fth/r/0ebRdtGJN6hnNt00WxB+8pxKlu8y2Zjah3urXwGeZ2A8JIEuZNAzC80uvQ WlIeepmVse9WxaI/b//9J8xcsfewNrgxojbn1H3/NNwIMlcpN4bkj5HIqNF8ZUH7 RIuoI+MZZ6xj4SnJhmTgjSUiB7Us6pTFEBBECy0F6SLzOou0dnNdl49ruiqElAT2 F+J3iD96h5jsthaHd4CmCy/27vk8MDfgaFFPUXHpqcgipDVinxSZyXQCY0WIlNaK tnoNdc9MIJfm8YDvhpRbBPlK5Ig== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we3231h1r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:39 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGc3b025583 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:38 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:37 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:42 -0800 Subject: [PATCH v17 19/35] arch/mm: Export direct {un,}map functions MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-19-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: MP-x340LqCsOeMxuGX6zrotY1v88l2Gs X-Proofpoint-GUID: MP-x340LqCsOeMxuGX6zrotY1v88l2Gs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 clxscore=1015 suspectscore=0 malwarescore=0 mlxlogscore=828 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220178 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 88B22C0005 X-Stat-Signature: fmkka93hj5dzi5us6pjqmz6ippbmjyg7 X-HE-Tag: 1708643806-194854 X-HE-Meta: U2FsdGVkX194kOxJUTTXjibAQ1V68V15/oLktnfFkWmhMCKdu50qWVInempMK2OYP9pPMgGcUMFuAwxaqdJxThuS1ZyAwXO4Cu4thKiZrW14sMq1qeXUz0OF8ckMsdBgI223hh1boHatAX9bQnBhy3zFbz05vbSlhwW8XsIBBpuVEACfDsCAM2ouvyIzGYM6cuyJGlqkqDpFTQoXuSLrZ2TQSK9UERpD+RCPCLfR/XfCuUiPgY4Z8jhwVWnpwsc84AszpCC/Q2TRCMLO3DWE/PdcgSgLJkXl8hM/Pp1mm7je4idsDtNK8k2ZlzHP+/BBNxqFI2/upntZs7tQLJgv2gNJ9ELvb59Di28pIJiiRfTuZkSgha5VVzz0o5ShVcskHR6oMtKFsx4nmzPL8cyqXtfWaVGSCpvxPVAQTCciq3mx08OQzH1qEo+TuEIWeoGUVPJJoFUvaBCjM+aljGzbA/+/z/RccVZYIsD1sm/Xat1HDsK7K1ONYCQU8+BnEPV9LiPDdDTaxSlUaPYVA4+lN3QY2kpQ5pZhAFetoJOJoomURonLyiappneCy+kVfcRi44Oi3DZz11wepWZj8p9XqQmC/OjeZZuYOaYRwqdj+ib2f+lB/IYp6Us6cc5tCTSeeIDv5p0MgfciPFJa8/uRMn38mE8lzKPGRrH9u3LTxCxvrw3vzxfgEXM5hk/PDcS1yA8pWnDFYwGktx4rWqAmDhaKehyUW2eAUUMEAznW73XV5fR6cyDr8BIwB2ZgJchbAduiiGxGiBefEOZn9YRgmT9nR3XHZZQ0Sat5+66+1xW/G2JkeAgvjjXvmPtYmPTbadJYoSl90v6S7nzyClredbOEwv45joVW/1dTMOBbgXJwPxHtduUVYdqN2+1bYOne/jbwM/rumYTDSxQfZ1xEWbG9kYwJteJs4TohC7vwFAmlyFtdR6Z5oetZRHMCcT0bClWuLj1KC6k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Firmware and hypervisor drivers can donate system heap memory to their respective firmware/hypervisor entities. Those drivers should unmap the pages from the kernel's logical map before doing so. Export can_set_direct_map, set_direct_map_invalid_noflush, and set_direct_map_default_noflush. Signed-off-by: Elliot Berman --- arch/arm64/mm/pageattr.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c index 924843f1f661b..a9bd84588c98a 100644 --- a/arch/arm64/mm/pageattr.c +++ b/arch/arm64/mm/pageattr.c @@ -32,6 +32,7 @@ bool can_set_direct_map(void) return rodata_full || debug_pagealloc_enabled() || arm64_kfence_can_set_direct_map(); } +EXPORT_SYMBOL_GPL(can_set_direct_map); static int change_page_range(pte_t *ptep, unsigned long addr, void *data) { @@ -176,6 +177,7 @@ int set_direct_map_invalid_noflush(struct page *page) (unsigned long)page_address(page), PAGE_SIZE, change_page_range, &data); } +EXPORT_SYMBOL_GPL(set_direct_map_invalid_noflush); int set_direct_map_default_noflush(struct page *page) { @@ -191,6 +193,7 @@ int set_direct_map_default_noflush(struct page *page) (unsigned long)page_address(page), PAGE_SIZE, change_page_range, &data); } +EXPORT_SYMBOL_GPL(set_direct_map_default_noflush); #ifdef CONFIG_DEBUG_PAGEALLOC void __kernel_map_pages(struct page *page, int numpages, int enable) From patchwork Thu Feb 22 23:16:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568242 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E36EC54798 for ; Thu, 22 Feb 2024 23:17:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0362B6B009E; Thu, 22 Feb 2024 18:16:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F1FEC6B00A2; Thu, 22 Feb 2024 18:16:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9FA16B009F; Thu, 22 Feb 2024 18:16:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9FC856B00A0 for ; Thu, 22 Feb 2024 18:16:51 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5FE1140FC5 for ; Thu, 22 Feb 2024 23:16:51 +0000 (UTC) X-FDA: 81821001822.20.0524B1F Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf30.hostedemail.com (Postfix) with ESMTP id 269EE80008 for ; Thu, 22 Feb 2024 23:16:48 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=kYZ0NPcm; spf=pass (imf30.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643809; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=clAk92Ts/gD4QHs5sYWqn8ISRpZoQmyjiENZJzV8DqQ=; b=3I2jGuALvEcxZhb1KjmEQafvCaBDsGH19OHZZ+9q8zQ0+H53j5s/PFukxbMsoFt4IfO7zQ ZfknKWWvuOtAvAonmFYHg214gB0Nr2Jvy/kOQ8ZZnhJJ8XYjPrJ9zafNmFmuE1vOXMyH2I AG85tNFdCEQMzX2I/odU8C5iu7gkV9E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643809; a=rsa-sha256; cv=none; b=qzwGTELIcCXhdQfbstiLvA3NzXsN4a/yRAQuYVLvAtdG9OJ2s8dDYUfeckvzS1dAigjaJh F6VK7jr3lkmA0wmlEk1CZudggFOYihZa9ORyabjHNcmhtl1nQ087NDI4aPZ3BCnQ3gBRnr QKQmL1quDSu4W8GZT9rtk7bZQjvx8rQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=kYZ0NPcm; spf=pass (imf30.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMmLNi024971; Thu, 22 Feb 2024 23:16:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=clAk92Ts/gD4QHs5sYWqn8ISRpZoQmyjiENZJzV8DqQ =; b=kYZ0NPcmaA3IQmPoyh/tGEySC/EtYDT3lp4a/ED4uDGesLmo6/KxNex9ntd b0K2O5PQUlNnwoYocKSu36PgeUlCIPDzYLPxEnKJv444+ZI9Q1t4swhI35UJkiqY azvtDZKYjndNDrAtI61XUnPC8NiPlTruu4OXbX9WusMAySigUlDJ1OqkhR1+q4V+ kB4m794ZMuGQoG0WWoh2nTpMg1KvX+RYtOu9xxQ6JEDPrq1uBHYPh3Kuw1aPLA+R cRp9X7n5iPMB52Va7PojEMDUqRowLyiWSHRbHhXtKNP3kVzxmXpN74AT3p0FzDDJ cFLN3xtl65mCWTbeYBtSI7rwtiQ== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we2bxas2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:39 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGcNX018249 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:38 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:38 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:43 -0800 Subject: [PATCH v17 20/35] virt: gunyah: Add interfaces to map memory into guest address space MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-20-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: sFEbr7ut23zkwdVo9ocPmS2RpLrKc_NX X-Proofpoint-GUID: sFEbr7ut23zkwdVo9ocPmS2RpLrKc_NX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 adultscore=0 phishscore=0 clxscore=1015 malwarescore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: 269EE80008 X-Rspam-User: X-Stat-Signature: 7qwmajthdeqcdhaxcq3t3qyr969gyy1d X-Rspamd-Server: rspam03 X-HE-Tag: 1708643808-426951 X-HE-Meta: U2FsdGVkX19GaF2GFKePBAawna/pHhpOpQFDMuPpYhvkGmdwSrBsMnOKbG2EI1Fgwtj+pNXsw7WvvVw0wUZvCL6m/mgnOBuB25Ins9fuEsV460x3VXvz8NNwTP1L+OVaMqDo9vydk8h6XFrcoz4u4qxmvaUah0wppvKWOY6fi6spm1wqxEQe8w8Ibm6cHDmt1RvqQHFh+CekBnuhLHLdpj8uKQvVfOOrALAaqDgjwkaycpUkLZ+KTMBeN8aze+i/e4ZY8GSjVEAbGS9iZW9R6VFK7qluWpGiIkPj/5NcrD6hUl0F/HczBII2jWrZPooYkZeH2qUO9h92DFINxFOtLmALPpAPAEfAjnVT6IblUNbszM+eNS3XSHY+RtcwKJJQ3A5niq2322HtfRRtScRdHYHmJy9CyJnm7hnKJTglY/hvwDCVUmMa1PLnMLQA2MtzruNV3kigSNlXJPSo6MMWV2UmD9x8SrW8Qa8flvFEF0NG7y469WssVBbKNzSg/fTNk+VRJ4bGpfcocWTqqrID2vG80gPaJ7fFcRU5xekgbXs+9xY+uuk+BEVnjDlNbgilk12tquPpDlbHAQ9CzCSLEn15nnDovQRi0PSDR7QgcdG6zyi5Rxoqi8FTeD7DLLswDioMHdNTHpVcXB3WOvXjZGCf9YSg62kSrwZ+GD9krhTIYYS1+Mrlw1O+FRfnTvUbk1T66uxtvFzspqh/VWOmPwPprc/NRvPzFrqu0r8Z2zhIwI/8lxab0oVZjDcPff38Rp/CTEQYdp8A2Vwfuxi49jwcg614Uu9gxxXq7QKcVPu6tTqUGZ2i5fBHXJXQbVFB4C38jD47FE9YRZFz4zjplNORFp+S1n2nKyhZMvIGt5pL9Trq0bW9K9g1/5zNZKwRPRNufg17tE4qZ0yOpx5M9htNe8nt8uWDcimcQuDYDP5Rw+bTPonhfWh70CgeuK4FitbFTzCzty6KI9bfRcD lCBOL4ld aC6QFM8j1EaBrv8qm/GC8wqN6Qp+QsXdAoNaliL8ah/q+qBYVvTWRLh2hSyrESKxDHIuKdm9qcb0di/d5iHVbUVZmnZxQ6mxyPuzND1e90M6YkIEGXhDusklz1aoac6mQLCOAp1oM1MNWI+WotE7b4LMpes97bv99gRp1QJmwleZq2yWKzKZrznMgikJXttNo1ypRgJCr3E0fBbUZ4X5+pxOloJULfdfq6fiHUJNl6hEE3aAc/Us1k0mUpu0bEUU4+6KWjP0ifkL4M5SxgixTh3tN7T9QRdUVCnaOv+Il184k6/nx8WWCN+PM/PblaF+BQ+gz7laxYjZRQhldC9kX1Eov5dyXegGeVynweKtrjq95TU8jqaqci68jQWCifQscicR75TX8gBUxU1BMY7j+xx6Bug== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Gunyah virtual machines are created with either all memory provided at VM creation using the Resource Manager memory parcel construct, or Incrementally by enabling VM demand paging. The Gunyah demand paging support is provided directly by the hypervisor and does not require the creation of resource manager memory parcels. Demand paging allows the host to map/unmap contiguous pages (folios) to a Gunyah memory extent object with the correct rights allowing its contained pages to be mapped into the Guest VM's address space. Memory extents are Gunyah's mechanism for handling system memory abstracting from the direct use of physical page numbers. Memory extents are hypervisor objects and are therefore referenced and access controlled with capabilities. When a virtual machine is configured for demand paging, 3 memory extent and 1 address space capabilities are provided to the host. The resource manager defined policy is such that memory in the "host-only" extent (the default) is private to the host. Memory in the "guest-only" extent can be used for guest private mappings, and are unmapped from the host. Memory in the "host-and-guest-shared" extent can be mapped concurrently and shared between the host and guest VMs. Implement two functions which Linux can use to move memory between the virtual machines: gunyah_provide_folio and gunyah_reclaim_folio. Memory that has been provided to the guest is tracked in a maple tree to be reclaimed later. Folios provided to the virtual machine are assumed to be owned Gunyah stack: the folio's ->private field is used for bookkeeping about whether page is mapped into virtual machine. Signed-off-by: Elliot Berman --- drivers/virt/gunyah/Makefile | 2 +- drivers/virt/gunyah/vm_mgr.c | 69 +++++++++ drivers/virt/gunyah/vm_mgr.h | 108 +++++++++++++ drivers/virt/gunyah/vm_mgr_mem.c | 321 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 499 insertions(+), 1 deletion(-) diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index 3f82af8c5ce79..f3c9507224eeb 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o +gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o vm_mgr_mem.o obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o gunyah_vcpu.o diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index a6e25901dcea3..64967a8b72885 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -17,6 +17,16 @@ #include "rsc_mgr.h" #include "vm_mgr.h" +#define GUNYAH_VM_ADDRSPACE_LABEL 0 +// "To" extent for memory private to guest +#define GUNYAH_VM_MEM_EXTENT_GUEST_PRIVATE_LABEL 0 +// "From" extent for memory shared with guest +#define GUNYAH_VM_MEM_EXTENT_HOST_SHARED_LABEL 1 +// "To" extent for memory shared with the guest +#define GUNYAH_VM_MEM_EXTENT_GUEST_SHARED_LABEL 3 +// "From" extent for memory private to guest +#define GUNYAH_VM_MEM_EXTENT_HOST_PRIVATE_LABEL 2 + static DEFINE_XARRAY(gunyah_vm_functions); static void gunyah_vm_put_function(struct gunyah_vm_function *fn) @@ -175,6 +185,16 @@ void gunyah_vm_function_unregister(struct gunyah_vm_function *fn) } EXPORT_SYMBOL_GPL(gunyah_vm_function_unregister); +static bool gunyah_vm_resource_ticket_populate_noop( + struct gunyah_vm_resource_ticket *ticket, struct gunyah_resource *ghrsc) +{ + return true; +} +static void gunyah_vm_resource_ticket_unpopulate_noop( + struct gunyah_vm_resource_ticket *ticket, struct gunyah_resource *ghrsc) +{ +} + int gunyah_vm_add_resource_ticket(struct gunyah_vm *ghvm, struct gunyah_vm_resource_ticket *ticket) { @@ -349,6 +369,17 @@ static void gunyah_vm_stop(struct gunyah_vm *ghvm) ghvm->vm_status != GUNYAH_RM_VM_STATUS_RUNNING); } +static inline void setup_extent_ticket(struct gunyah_vm *ghvm, + struct gunyah_vm_resource_ticket *ticket, + u32 label) +{ + ticket->resource_type = GUNYAH_RESOURCE_TYPE_MEM_EXTENT; + ticket->label = label; + ticket->populate = gunyah_vm_resource_ticket_populate_noop; + ticket->unpopulate = gunyah_vm_resource_ticket_unpopulate_noop; + gunyah_vm_add_resource_ticket(ghvm, ticket); +} + static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) { struct gunyah_vm *ghvm; @@ -372,6 +403,25 @@ static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) INIT_LIST_HEAD(&ghvm->resources); INIT_LIST_HEAD(&ghvm->resource_tickets); + mt_init(&ghvm->mm); + + ghvm->addrspace_ticket.resource_type = GUNYAH_RESOURCE_TYPE_ADDR_SPACE; + ghvm->addrspace_ticket.label = GUNYAH_VM_ADDRSPACE_LABEL; + ghvm->addrspace_ticket.populate = + gunyah_vm_resource_ticket_populate_noop; + ghvm->addrspace_ticket.unpopulate = + gunyah_vm_resource_ticket_unpopulate_noop; + gunyah_vm_add_resource_ticket(ghvm, &ghvm->addrspace_ticket); + + setup_extent_ticket(ghvm, &ghvm->host_private_extent_ticket, + GUNYAH_VM_MEM_EXTENT_HOST_PRIVATE_LABEL); + setup_extent_ticket(ghvm, &ghvm->host_shared_extent_ticket, + GUNYAH_VM_MEM_EXTENT_HOST_SHARED_LABEL); + setup_extent_ticket(ghvm, &ghvm->guest_private_extent_ticket, + GUNYAH_VM_MEM_EXTENT_GUEST_PRIVATE_LABEL); + setup_extent_ticket(ghvm, &ghvm->guest_shared_extent_ticket, + GUNYAH_VM_MEM_EXTENT_GUEST_SHARED_LABEL); + return ghvm; } @@ -533,6 +583,23 @@ static void _gunyah_vm_put(struct kref *kref) gunyah_vm_stop(ghvm); gunyah_vm_remove_functions(ghvm); + + /** + * If this fails, we're going to lose the memory for good and is + * BUG_ON-worthy, but not unrecoverable (we just lose memory). + * This call should always succeed though because the VM is in not + * running and RM will let us reclaim all the memory. + */ + WARN_ON(gunyah_vm_reclaim_range(ghvm, 0, U64_MAX)); + + /* clang-format off */ + gunyah_vm_remove_resource_ticket(ghvm, &ghvm->addrspace_ticket); + gunyah_vm_remove_resource_ticket(ghvm, &ghvm->host_shared_extent_ticket); + gunyah_vm_remove_resource_ticket(ghvm, &ghvm->host_private_extent_ticket); + gunyah_vm_remove_resource_ticket(ghvm, &ghvm->guest_shared_extent_ticket); + gunyah_vm_remove_resource_ticket(ghvm, &ghvm->guest_private_extent_ticket); + /* clang-format on */ + gunyah_vm_clean_resources(ghvm); if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_EXITED || @@ -548,6 +615,8 @@ static void _gunyah_vm_put(struct kref *kref) /* clang-format on */ } + mtree_destroy(&ghvm->mm); + if (ghvm->vm_status > GUNYAH_RM_VM_STATUS_NO_STATE) { gunyah_rm_notifier_unregister(ghvm->rm, &ghvm->nb); diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index 8c5b94101b2cf..a6a4efa4138b7 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -8,20 +8,53 @@ #include #include +#include #include +#include #include +#include #include #include #include "rsc_mgr.h" +static inline u64 gunyah_gpa_to_gfn(u64 gpa) +{ + return gpa >> PAGE_SHIFT; +} + +static inline u64 gunyah_gfn_to_gpa(u64 gfn) +{ + return gfn << PAGE_SHIFT; +} + long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, unsigned long arg); /** * struct gunyah_vm - Main representation of a Gunyah Virtual machine * @vmid: Gunyah's VMID for this virtual machine + * @mm: A maple tree of all memory that has been mapped to a VM. + * Indices are guest frame numbers; entries are either folios or + * RM mem parcels + * @addrspace_ticket: Resource ticket to the capability for guest VM's + * address space + * @host_private_extent_ticket: Resource ticket to the capability for our + * memory extent from which to lend private + * memory to the guest + * @host_shared_extent_ticket: Resource ticket to the capaiblity for our + * memory extent from which to share memory + * with the guest. Distinction with + * @host_private_extent_ticket needed for + * current Qualcomm platforms; on non-Qualcomm + * platforms, this is the same capability ID + * @guest_private_extent_ticket: Resource ticket to the capaiblity for + * the guest's memory extent to lend private + * memory to + * @guest_shared_extent_ticket: Resource ticket to the capability for + * the memory extent that represents + * memory shared with the guest. * @rm: Pointer to the resource manager struct to make RM calls * @parent: For logging * @nb: Notifier block for RM notifications @@ -43,6 +76,11 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, */ struct gunyah_vm { u16 vmid; + struct maple_tree mm; + struct gunyah_vm_resource_ticket addrspace_ticket, + host_private_extent_ticket, host_shared_extent_ticket, + guest_private_extent_ticket, guest_shared_extent_ticket; + struct gunyah_rm *rm; struct notifier_block nb; @@ -63,4 +101,74 @@ struct gunyah_vm { }; +/** + * folio_mmapped() - Returns true if the folio is mapped into any vma + * @folio: Folio to test + */ +static bool folio_mmapped(struct folio *folio) +{ + struct address_space *mapping = folio->mapping; + struct vm_area_struct *vma; + bool ret = false; + + i_mmap_lock_read(mapping); + vma_interval_tree_foreach(vma, &mapping->i_mmap, folio_index(folio), + folio_index(folio) + folio_nr_pages(folio)) { + ret = true; + break; + } + i_mmap_unlock_read(mapping); + return ret; +} + +/** + * gunyah_folio_lend_safe() - Returns true if folio is ready to be lent to guest + * @folio: Folio to prepare + * + * Tests if the folio is mapped anywhere outside the kernel logical map + * and whether any userspace has a vma containing the folio, even if it hasn't + * paged it in. We want to avoid causing fault to userspace. + * If userspace doesn't have it mapped anywhere, then unmap from kernel + * logical map to prevent accidental access (e.g. by load_unaligned_zeropad) + */ +static inline bool gunyah_folio_lend_safe(struct folio *folio) +{ + long i; + + if (folio_mapped(folio) || folio_mmapped(folio)) + return false; + + for (i = 0; i < folio_nr_pages(folio); i++) + set_direct_map_invalid_noflush(folio_page(folio, i)); + /** + * No need to flush tlb on armv8/9: hypervisor will flush when it + * removes from our stage 2 + */ + return true; +} + +/** + * gunyah_folio_host_reclaim() - Restores kernel logical map to folio + * @folio: folio to reclaim by host + * + * See also gunyah_folio_lend_safe(). + */ +static inline void gunyah_folio_host_reclaim(struct folio *folio) +{ + long i; + for (i = 0; i < folio_nr_pages(folio); i++) + set_direct_map_default_noflush(folio_page(folio, i)); +} + +int gunyah_vm_parcel_to_paged(struct gunyah_vm *ghvm, + struct gunyah_rm_mem_parcel *parcel, u64 gfn, + u64 nr); +void gunyah_vm_mm_erase_range(struct gunyah_vm *ghvm, u64 gfn, u64 nr); +int gunyah_vm_reclaim_parcel(struct gunyah_vm *ghvm, + struct gunyah_rm_mem_parcel *parcel, u64 gfn); +int gunyah_vm_provide_folio(struct gunyah_vm *ghvm, struct folio *folio, + u64 gfn, bool share, bool write); +int gunyah_vm_reclaim_folio(struct gunyah_vm *ghvm, u64 gfn, struct folio *folio); +int gunyah_vm_reclaim_range(struct gunyah_vm *ghvm, u64 gfn, u64 nr); + #endif diff --git a/drivers/virt/gunyah/vm_mgr_mem.c b/drivers/virt/gunyah/vm_mgr_mem.c new file mode 100644 index 0000000000000..bcc84473004be --- /dev/null +++ b/drivers/virt/gunyah/vm_mgr_mem.c @@ -0,0 +1,321 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) "gunyah_vm_mgr: " fmt + +#include +#include +#include + +#include "vm_mgr.h" + +#define WRITE_TAG (1 << 0) +#define SHARE_TAG (1 << 1) + +static inline struct gunyah_resource * +__first_resource(struct gunyah_vm_resource_ticket *ticket) +{ + return list_first_entry_or_null(&ticket->resources, + struct gunyah_resource, list); +} + +int gunyah_vm_parcel_to_paged(struct gunyah_vm *ghvm, + struct gunyah_rm_mem_parcel *parcel, u64 gfn, + u64 nr) +{ + struct gunyah_rm_mem_entry *entry; + unsigned long i, tag = 0; + struct folio *folio; + pgoff_t off = 0; + int ret; + + if (parcel->n_acl_entries > 1) + tag |= SHARE_TAG; + if (parcel->acl_entries[0].perms & GUNYAH_RM_ACL_W) + tag |= WRITE_TAG; + + for (i = 0; i < parcel->n_mem_entries; i++) { + entry = &parcel->mem_entries[i]; + + folio = pfn_folio(PHYS_PFN(le64_to_cpu(entry->phys_addr))); + ret = mtree_insert_range(&ghvm->mm, gfn + off, + gfn + off + folio_nr_pages(folio) - 1, + xa_tag_pointer(folio, tag), + GFP_KERNEL); + if (ret) { + WARN_ON(ret != -ENOMEM); + gunyah_vm_mm_erase_range(ghvm, gfn, off - 1); + return ret; + } + off += folio_nr_pages(folio); + } + + return 0; +} + +/** + * gunyah_vm_mm_erase_range() - Erases a range of folios from ghvm's mm + * @ghvm: gunyah vm + * @gfn: start guest frame number + * @nr: number of pages to erase + * + * Do not use this function unless rolling back gunyah_vm_parcel_to_paged. + */ +void gunyah_vm_mm_erase_range(struct gunyah_vm *ghvm, u64 gfn, u64 nr) +{ + struct folio *folio; + u64 off = gfn; + + while (off < gfn + nr) { + folio = xa_untag_pointer(mtree_erase(&ghvm->mm, off)); + if (!folio) + return; + off += folio_nr_pages(folio); + } +} + +static inline u32 donate_flags(bool share) +{ + if (share) + return FIELD_PREP_CONST(GUNYAH_MEMEXTENT_OPTION_TYPE_MASK, + GUNYAH_MEMEXTENT_DONATE_TO_SIBLING); + else + return FIELD_PREP_CONST(GUNYAH_MEMEXTENT_OPTION_TYPE_MASK, + GUNYAH_MEMEXTENT_DONATE_TO_PROTECTED); +} + +static inline u32 reclaim_flags(bool share) +{ + if (share) + return FIELD_PREP_CONST(GUNYAH_MEMEXTENT_OPTION_TYPE_MASK, + GUNYAH_MEMEXTENT_DONATE_TO_SIBLING); + else + return FIELD_PREP_CONST(GUNYAH_MEMEXTENT_OPTION_TYPE_MASK, + GUNYAH_MEMEXTENT_DONATE_FROM_PROTECTED); +} + +int gunyah_vm_provide_folio(struct gunyah_vm *ghvm, struct folio *folio, + u64 gfn, bool share, bool write) +{ + struct gunyah_resource *guest_extent, *host_extent, *addrspace; + u32 map_flags = BIT(GUNYAH_ADDRSPACE_MAP_FLAG_PARTIAL); + u64 extent_attrs, gpa = gunyah_gfn_to_gpa(gfn); + phys_addr_t pa = PFN_PHYS(folio_pfn(folio)); + enum gunyah_pagetable_access access; + size_t size = folio_size(folio); + enum gunyah_error gunyah_error; + unsigned long tag = 0; + int ret; + + /* clang-format off */ + if (share) { + guest_extent = __first_resource(&ghvm->guest_shared_extent_ticket); + host_extent = __first_resource(&ghvm->host_shared_extent_ticket); + } else { + guest_extent = __first_resource(&ghvm->guest_private_extent_ticket); + host_extent = __first_resource(&ghvm->host_private_extent_ticket); + } + /* clang-format on */ + addrspace = __first_resource(&ghvm->addrspace_ticket); + + if (!addrspace || !guest_extent || !host_extent) { + folio_unlock(folio); + return -ENODEV; + } + + if (share) { + map_flags |= BIT(GUNYAH_ADDRSPACE_MAP_FLAG_VMMIO); + tag |= SHARE_TAG; + } else { + map_flags |= BIT(GUNYAH_ADDRSPACE_MAP_FLAG_PRIVATE); + } + + if (write) + tag |= WRITE_TAG; + + ret = mtree_insert_range(&ghvm->mm, gfn, + gfn + folio_nr_pages(folio) - 1, + xa_tag_pointer(folio, tag), GFP_KERNEL); + if (ret == -EEXIST) + ret = -EAGAIN; + if (ret) + return ret; + + /* don't lend a folio that is (or could be) mapped by Linux */ + if (!share && !gunyah_folio_lend_safe(folio)) { + ret = -EPERM; + goto remove; + } + + if (share && write) + access = GUNYAH_PAGETABLE_ACCESS_RW; + else if (share && !write) + access = GUNYAH_PAGETABLE_ACCESS_R; + else if (!share && write) + access = GUNYAH_PAGETABLE_ACCESS_RWX; + else /* !share && !write */ + access = GUNYAH_PAGETABLE_ACCESS_RX; + + gunyah_error = gunyah_hypercall_memextent_donate(donate_flags(share), + host_extent->capid, + guest_extent->capid, + pa, size); + if (gunyah_error != GUNYAH_ERROR_OK) { + pr_err("Failed to donate memory for guest address 0x%016llx: %d\n", + gpa, gunyah_error); + ret = gunyah_error_remap(gunyah_error); + goto remove; + } + + extent_attrs = + FIELD_PREP_CONST(GUNYAH_MEMEXTENT_MAPPING_TYPE, + ARCH_GUNYAH_DEFAULT_MEMTYPE) | + FIELD_PREP(GUNYAH_MEMEXTENT_MAPPING_USER_ACCESS, access) | + FIELD_PREP(GUNYAH_MEMEXTENT_MAPPING_KERNEL_ACCESS, access); + gunyah_error = gunyah_hypercall_addrspace_map(addrspace->capid, + guest_extent->capid, gpa, + extent_attrs, map_flags, + pa, size); + if (gunyah_error != GUNYAH_ERROR_OK) { + pr_err("Failed to map guest address 0x%016llx: %d\n", gpa, + gunyah_error); + ret = gunyah_error_remap(gunyah_error); + goto memextent_reclaim; + } + + folio_get(folio); + if (!share) + folio_set_private(folio); + return 0; +memextent_reclaim: + gunyah_error = gunyah_hypercall_memextent_donate(reclaim_flags(share), + guest_extent->capid, + host_extent->capid, pa, + size); + if (gunyah_error != GUNYAH_ERROR_OK) + pr_err("Failed to reclaim memory donation for guest address 0x%016llx: %d\n", + gpa, gunyah_error); +remove: + mtree_erase(&ghvm->mm, gfn); + return ret; +} + +static int __gunyah_vm_reclaim_folio_locked(struct gunyah_vm *ghvm, void *entry, + u64 gfn, const bool sync) +{ + u32 map_flags = BIT(GUNYAH_ADDRSPACE_MAP_FLAG_PARTIAL); + struct gunyah_resource *guest_extent, *host_extent, *addrspace; + enum gunyah_error gunyah_error; + struct folio *folio; + bool write, share; + phys_addr_t pa; + size_t size; + int ret; + + addrspace = __first_resource(&ghvm->addrspace_ticket); + if (!addrspace) + return -ENODEV; + + share = !!(xa_pointer_tag(entry) & SHARE_TAG); + write = !!(xa_pointer_tag(entry) & WRITE_TAG); + folio = xa_untag_pointer(entry); + + if (!sync) + map_flags |= BIT(GUNYAH_ADDRSPACE_MAP_FLAG_NOSYNC); + + /* clang-format off */ + if (share) { + guest_extent = __first_resource(&ghvm->guest_shared_extent_ticket); + host_extent = __first_resource(&ghvm->host_shared_extent_ticket); + map_flags |= BIT(GUNYAH_ADDRSPACE_MAP_FLAG_VMMIO); + } else { + guest_extent = __first_resource(&ghvm->guest_private_extent_ticket); + host_extent = __first_resource(&ghvm->host_private_extent_ticket); + map_flags |= BIT(GUNYAH_ADDRSPACE_MAP_FLAG_PRIVATE); + } + /* clang-format on */ + + pa = PFN_PHYS(folio_pfn(folio)); + size = folio_size(folio); + + gunyah_error = gunyah_hypercall_addrspace_unmap(addrspace->capid, + guest_extent->capid, + gunyah_gfn_to_gpa(gfn), + map_flags, pa, size); + if (gunyah_error != GUNYAH_ERROR_OK) { + pr_err_ratelimited( + "Failed to unmap guest address 0x%016llx: %d\n", + gunyah_gfn_to_gpa(gfn), gunyah_error); + ret = gunyah_error_remap(gunyah_error); + goto err; + } + + gunyah_error = gunyah_hypercall_memextent_donate(reclaim_flags(share), + guest_extent->capid, + host_extent->capid, pa, + size); + if (gunyah_error != GUNYAH_ERROR_OK) { + pr_err_ratelimited( + "Failed to reclaim memory donation for guest address 0x%016llx: %d\n", + gunyah_gfn_to_gpa(gfn), gunyah_error); + ret = gunyah_error_remap(gunyah_error); + goto err; + } + + BUG_ON(mtree_erase(&ghvm->mm, gfn) != entry); + + if (folio_test_private(folio)) { + gunyah_folio_host_reclaim(folio); + folio_clear_private(folio); + } + + folio_put(folio); + return 0; +err: + return ret; +} + +int gunyah_vm_reclaim_folio(struct gunyah_vm *ghvm, u64 gfn, struct folio *folio) +{ + void *entry; + + entry = mtree_load(&ghvm->mm, gfn); + if (!entry) + return 0; + + if (folio != xa_untag_pointer(entry)) + return -EAGAIN; + + return __gunyah_vm_reclaim_folio_locked(ghvm, entry, gfn, true); +} + +int gunyah_vm_reclaim_range(struct gunyah_vm *ghvm, u64 gfn, u64 nr) +{ + unsigned long next = gfn, g; + struct folio *folio; + int ret, ret2 = 0; + void *entry; + bool sync; + + mt_for_each(&ghvm->mm, entry, next, gfn + nr) { + folio = xa_untag_pointer(entry); + g = next; + sync = !!mt_find_after(&ghvm->mm, &g, gfn + nr); + + g = next - folio_nr_pages(folio); + folio_get(folio); + folio_lock(folio); + if (mtree_load(&ghvm->mm, g) == entry) + ret = __gunyah_vm_reclaim_folio_locked(ghvm, entry, g, sync); + else + ret = -EAGAIN; + folio_unlock(folio); + folio_put(folio); + if (ret && ret2 != -EAGAIN) + ret2 = ret; + } + + return ret2; +} From patchwork Thu Feb 22 23:16:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36186C47DD9 for ; Thu, 22 Feb 2024 23:17:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D030D6B009F; Thu, 22 Feb 2024 18:16:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C8BA96B00A1; Thu, 22 Feb 2024 18:16:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB8F26B00A2; Thu, 22 Feb 2024 18:16:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8E53B6B009F for ; Thu, 22 Feb 2024 18:16:52 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 67DEE1C122E for ; Thu, 22 Feb 2024 23:16:52 +0000 (UTC) X-FDA: 81821001864.12.615FEDD Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf10.hostedemail.com (Postfix) with ESMTP id 21F6DC001D for ; Thu, 22 Feb 2024 23:16:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=SR9SpbtC; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf10.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643810; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jVo09/u52xKS3SRP+ridwNYZaY+tDvXa3dwfznZpMSA=; b=CZPVOrwKi2lgMiUNWlwC7513CFl41IyMzyM0FwVrfwn9kd9GlsffqRsy+86Zd2FDsRX9Io liszzy8T3PLazfI6DvAW09tBjXONeuCrqsF/zZKyXr6HdBNDndwygq5O/y8AwUHYaPk0gH e+jLMbOy4op3RpdjHvs3gJ8r9MgBZHY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=SR9SpbtC; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf10.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643810; a=rsa-sha256; cv=none; b=aOCTg95EWMPZ5QbQjNSBpM4bYWbd7bqUzNwE3/b4X8fzwD9wpi2Uj5fYVrAXJZUzKUpILW hMpTy0crwBjQ32T063qmNcg4qgBm/maahsLtoK83w/duBZC2V1DKyX/9lYS1P9x7CH64oP /xzVs8Riyl5DewNODyg7TawrnIhajEQ= Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMxSGX017355; Thu, 22 Feb 2024 23:16:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=jVo09/u52xKS3SRP+ridwNYZaY+tDvXa3dwfznZpMSA =; b=SR9SpbtCK3RJoI6pmPizVQ/1cN+SIGggZje2hd7SLOIPkKWH6PRHeOGXwic U362InafOqvSN5BBSTlmatkSf+Poe81sh7LheYO+wgHsYRmThnzHMZMQL/88BQGf gOgr+hx9PZCbHEiRcfO7E1Kc24mwZsw/Isna8kQEWqKenHuV/hI4TAAjwncLiGwK 09ukalV3//bGcUvvWyVC5wy7G4FSXomXONadpMOlOvKP8OTvl1as/IH7he2aIFc7 Qm921En7tkQfEDMXN6u580V9q+kbZaKuQ69SqxGdoPDa3liMRnX1feebSG+GmUKt 24etU0UED5lGzSJY+0RQFAX4x6w== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we1b0jxsw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:39 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGdgD018255 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:39 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:38 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:44 -0800 Subject: [PATCH v17 21/35] gunyah: rsc_mgr: Add platform ops on mem_lend/mem_reclaim MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-21-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: w0XRV1HAULetVECwnmYzVyZ97RenARDd X-Proofpoint-GUID: w0XRV1HAULetVECwnmYzVyZ97RenARDd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Stat-Signature: hb3r6nd6ietdh4wjs1f5gtjazho61aey X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 21F6DC001D X-HE-Tag: 1708643809-410702 X-HE-Meta: U2FsdGVkX19ufLLMeU6tKQHGBrv/Mrx3UwTNFGNsVfeLGdRMvrloBrWt71XPDxe+F7sbVrVspWIc0jVms+e+nbM3ZCK023/0+nNoSZbA2MmkPOBghL35VPI2t/z7qBPkv+8sYqzVzmG2QjYrf0AVtK7QklCGKFahOesHLsN2cuawdgxMMEvIx4JQAHzOwxlGRyf8PsIcDrps3sPJwrG3bkZpIBjJsRee0VEQy1rmsYrPeclkZSU9eftV6kS1hoUxS124f0mJnkHP6qLTTzg6ZuMEgDgD/AnWmoY1/Pd9c+KyPQd3xhbufJ2yA0P+tK70WGP9U3lahBwtSe8R+Gj1NRbcdRqop21KTXLTVGfm3haiQeLD2Vj+IMIj0gdJZLi1S7s9djZPG4nv/eqjnCqLDw02BgVRUFwkX5VKE2El1lOdMXECOblAQ8BoPBBd0QF+RDcvJgSxKZD/fy37pXLryHnYuJ/1wPymNbNqB37Q7JzHke6IADk0B5T4EYfKysOkH2CsjjcyJlnHDila3CvDzIOuaObP/9HxMOlAV5mPNc/KacOGObcFPDKTPxSjeNrM8zPId57BvNhA2Dsv2pWVF4j9GJZGBB3o2Je0SmWOYiVbkwuGIhdYxdT0GDQP/jtoR2A9NItfhrMplwIwm0lFeZ1tW/wdOskk3EfZjgDo+/ao8tbIYX6Y9d8SdbI8Zdb55sNI8IQMZwQKJNAnWguVg+UkGsnm8dCS5SGxCcBx8SXpZwbf1MeS1SslhEmCggCOYBIFARq01i0fIFsjit2bQ06bczXN9iYakoNbE4YxPuqUBrvfb9g4Zv1EPt9qWNCBvf0I0126tCiqoG+c12xCtlaMe11eA6hKnex9ykNAUEoF/3cxRqGdUaxi96hTAW1EcdiiMuSKWMAyzj5M3qy5hzaTSHmA1eYIbJS8yGw6hxbC8ucrBBZlSM5iYM2Ti9+2TwjSZwBSWWK292/e4+P yJZMnpUY XdW+S6bhUhlR+/3kkmCMfPge+elyQYQjv6cLoWvymwuabKxgS9vyyivOfWG60oES/Saaxois0xy5EbOHfQka4lEdTX613I2/N0CqLfkDhCuF5jPLl+fU+xJ/Wf+BysYa8sP3rl7GjulqtzcY6m4o5cAuWhjwQGLisgG/B7BRr2LsrczpZLrAiQH5lSiKaGvOSqwtgi+KYt1m3j3J3IjQuO1FYCj11ZeXCc1i2p7uxffkypkBP7RpuKW78aRpGtGOUPW9gt4YXMntTxV8vOQ8XKEI4QDlWX84yb3ZiZ+nmJaqabUi94HsWOqHt5tXtQ9o2IvXR+hM2p/hi3xuDXrAvjGdy7YpMNdgyXwTmb/xoTgNdmmEcAiU+YfZOrHXCrHuQUV0NVTaK8HFB5+2/zYt+lEhwHIMuqvWsV9Z6xITk9PQQ3+U1pgZYq30vwWzwnujJSmiM X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Qualcomm platforms, there is a firmware entity which controls access to physical pages. In order to share memory with another VM, this entity needs to be informed that the guest VM should have access to the memory. Co-developed-by: Prakruthi Deepak Heragu Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman --- drivers/virt/gunyah/Kconfig | 4 + drivers/virt/gunyah/Makefile | 1 + drivers/virt/gunyah/gunyah_platform_hooks.c | 117 ++++++++++++++++++++++++++++ drivers/virt/gunyah/rsc_mgr.h | 10 +++ drivers/virt/gunyah/rsc_mgr_rpc.c | 20 ++++- drivers/virt/gunyah/vm_mgr_mem.c | 39 +++++++++- include/linux/gunyah.h | 63 ++++++++++++--- 7 files changed, 237 insertions(+), 17 deletions(-) diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig index 6f4c85db80b52..23ba523d25dc8 100644 --- a/drivers/virt/gunyah/Kconfig +++ b/drivers/virt/gunyah/Kconfig @@ -3,6 +3,7 @@ config GUNYAH tristate "Gunyah Virtualization drivers" depends on ARM64 + select GUNYAH_PLATFORM_HOOKS help The Gunyah drivers are the helper interfaces that run in a guest VM such as basic inter-VM IPC and signaling mechanisms, and higher level @@ -10,3 +11,6 @@ config GUNYAH Say Y/M here to enable the drivers needed to interact in a Gunyah virtual environment. + +config GUNYAH_PLATFORM_HOOKS + tristate diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index f3c9507224eeb..ffcde0e0ccfa9 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -3,3 +3,4 @@ gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o vm_mgr_mem.o obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o gunyah_vcpu.o +obj-$(CONFIG_GUNYAH_PLATFORM_HOOKS) += gunyah_platform_hooks.o diff --git a/drivers/virt/gunyah/gunyah_platform_hooks.c b/drivers/virt/gunyah/gunyah_platform_hooks.c new file mode 100644 index 0000000000000..b03795df00144 --- /dev/null +++ b/drivers/virt/gunyah/gunyah_platform_hooks.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include + +#include "rsc_mgr.h" + +static const struct gunyah_rm_platform_ops *rm_platform_ops; +static DECLARE_RWSEM(rm_platform_ops_lock); + +int gunyah_rm_platform_pre_mem_share(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *mem_parcel) +{ + int ret = 0; + + down_read(&rm_platform_ops_lock); + if (rm_platform_ops && rm_platform_ops->pre_mem_share) + ret = rm_platform_ops->pre_mem_share(rm, mem_parcel); + up_read(&rm_platform_ops_lock); + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_rm_platform_pre_mem_share); + +int gunyah_rm_platform_post_mem_reclaim(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *mem_parcel) +{ + int ret = 0; + + down_read(&rm_platform_ops_lock); + if (rm_platform_ops && rm_platform_ops->post_mem_reclaim) + ret = rm_platform_ops->post_mem_reclaim(rm, mem_parcel); + up_read(&rm_platform_ops_lock); + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_rm_platform_post_mem_reclaim); + +int gunyah_rm_platform_pre_demand_page(struct gunyah_rm *rm, u16 vmid, + enum gunyah_pagetable_access access, + struct folio *folio) +{ + int ret = 0; + + down_read(&rm_platform_ops_lock); + if (rm_platform_ops && rm_platform_ops->pre_demand_page) + ret = rm_platform_ops->pre_demand_page(rm, vmid, access, folio); + up_read(&rm_platform_ops_lock); + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_rm_platform_pre_demand_page); + +int gunyah_rm_platform_reclaim_demand_page(struct gunyah_rm *rm, u16 vmid, + enum gunyah_pagetable_access access, + struct folio *folio) +{ + int ret = 0; + + down_read(&rm_platform_ops_lock); + if (rm_platform_ops && rm_platform_ops->pre_demand_page) + ret = rm_platform_ops->release_demand_page(rm, vmid, access, + folio); + up_read(&rm_platform_ops_lock); + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_rm_platform_reclaim_demand_page); + +int gunyah_rm_register_platform_ops( + const struct gunyah_rm_platform_ops *platform_ops) +{ + int ret = 0; + + down_write(&rm_platform_ops_lock); + if (!rm_platform_ops) + rm_platform_ops = platform_ops; + else + ret = -EEXIST; + up_write(&rm_platform_ops_lock); + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_rm_register_platform_ops); + +void gunyah_rm_unregister_platform_ops( + const struct gunyah_rm_platform_ops *platform_ops) +{ + down_write(&rm_platform_ops_lock); + if (rm_platform_ops == platform_ops) + rm_platform_ops = NULL; + up_write(&rm_platform_ops_lock); +} +EXPORT_SYMBOL_GPL(gunyah_rm_unregister_platform_ops); + +static void _devm_gunyah_rm_unregister_platform_ops(void *data) +{ + gunyah_rm_unregister_platform_ops( + (const struct gunyah_rm_platform_ops *)data); +} + +int devm_gunyah_rm_register_platform_ops( + struct device *dev, const struct gunyah_rm_platform_ops *ops) +{ + int ret; + + ret = gunyah_rm_register_platform_ops(ops); + if (ret) + return ret; + + return devm_add_action(dev, _devm_gunyah_rm_unregister_platform_ops, + (void *)ops); +} +EXPORT_SYMBOL_GPL(devm_gunyah_rm_register_platform_ops); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Platform Hooks"); diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index ec8ad8149e8ef..68d08d3cff02d 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -117,4 +117,14 @@ int gunyah_rm_call(struct gunyah_rm *rsc_mgr, u32 message_id, const void *req_buf, size_t req_buf_size, void **resp_buf, size_t *resp_buf_size); +int gunyah_rm_platform_pre_mem_share(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *mem_parcel); +int gunyah_rm_platform_post_mem_reclaim( + struct gunyah_rm *rm, struct gunyah_rm_mem_parcel *mem_parcel); + +int gunyah_rm_platform_pre_demand_page(struct gunyah_rm *rm, u16 vmid, + u32 flags, struct folio *folio); +int gunyah_rm_platform_reclaim_demand_page(struct gunyah_rm *rm, u16 vmid, + u32 flags, struct folio *folio); + #endif diff --git a/drivers/virt/gunyah/rsc_mgr_rpc.c b/drivers/virt/gunyah/rsc_mgr_rpc.c index eb06940bb3c53..99e5a3f1a5bb9 100644 --- a/drivers/virt/gunyah/rsc_mgr_rpc.c +++ b/drivers/virt/gunyah/rsc_mgr_rpc.c @@ -209,6 +209,12 @@ int gunyah_rm_mem_share(struct gunyah_rm *rm, struct gunyah_rm_mem_parcel *p) if (!msg) return -ENOMEM; + ret = gunyah_rm_platform_pre_mem_share(rm, p); + if (ret) { + kfree(msg); + return ret; + } + req_header = msg; acl = (void *)req_header + sizeof(*req_header); mem = (void *)acl + acl_size; @@ -234,8 +240,10 @@ int gunyah_rm_mem_share(struct gunyah_rm *rm, struct gunyah_rm_mem_parcel *p) &resp_size); kfree(msg); - if (ret) + if (ret) { + gunyah_rm_platform_post_mem_reclaim(rm, p); return ret; + } p->mem_handle = le32_to_cpu(*resp); kfree(resp); @@ -267,9 +275,15 @@ int gunyah_rm_mem_reclaim(struct gunyah_rm *rm, struct gunyah_rm_mem_release_req req = { .mem_handle = cpu_to_le32(parcel->mem_handle), }; + int ret; - return gunyah_rm_call(rm, GUNYAH_RM_RPC_MEM_RECLAIM, &req, sizeof(req), - NULL, NULL); + ret = gunyah_rm_call(rm, GUNYAH_RM_RPC_MEM_RECLAIM, &req, sizeof(req), + NULL, NULL); + /* Only call platform mem reclaim hooks if we reclaimed the memory */ + if (ret) + return ret; + + return gunyah_rm_platform_post_mem_reclaim(rm, parcel); } ALLOW_ERROR_INJECTION(gunyah_rm_mem_reclaim, ERRNO); diff --git a/drivers/virt/gunyah/vm_mgr_mem.c b/drivers/virt/gunyah/vm_mgr_mem.c index bcc84473004be..5a4ea2b1a12ee 100644 --- a/drivers/virt/gunyah/vm_mgr_mem.c +++ b/drivers/virt/gunyah/vm_mgr_mem.c @@ -9,6 +9,7 @@ #include #include +#include "rsc_mgr.h" #include "vm_mgr.h" #define WRITE_TAG (1 << 0) @@ -107,7 +108,7 @@ int gunyah_vm_provide_folio(struct gunyah_vm *ghvm, struct folio *folio, size_t size = folio_size(folio); enum gunyah_error gunyah_error; unsigned long tag = 0; - int ret; + int ret, tmp; /* clang-format off */ if (share) { @@ -158,6 +159,11 @@ int gunyah_vm_provide_folio(struct gunyah_vm *ghvm, struct folio *folio, else /* !share && !write */ access = GUNYAH_PAGETABLE_ACCESS_RX; + ret = gunyah_rm_platform_pre_demand_page(ghvm->rm, ghvm->vmid, access, + folio); + if (ret) + goto reclaim_host; + gunyah_error = gunyah_hypercall_memextent_donate(donate_flags(share), host_extent->capid, guest_extent->capid, @@ -166,7 +172,7 @@ int gunyah_vm_provide_folio(struct gunyah_vm *ghvm, struct folio *folio, pr_err("Failed to donate memory for guest address 0x%016llx: %d\n", gpa, gunyah_error); ret = gunyah_error_remap(gunyah_error); - goto remove; + goto platform_release; } extent_attrs = @@ -197,6 +203,16 @@ int gunyah_vm_provide_folio(struct gunyah_vm *ghvm, struct folio *folio, if (gunyah_error != GUNYAH_ERROR_OK) pr_err("Failed to reclaim memory donation for guest address 0x%016llx: %d\n", gpa, gunyah_error); +platform_release: + tmp = gunyah_rm_platform_reclaim_demand_page(ghvm->rm, ghvm->vmid, + access, folio); + if (tmp) { + pr_err("Platform failed to reclaim memory for guest address 0x%016llx: %d", + gpa, tmp); + return ret; + } +reclaim_host: + gunyah_folio_host_reclaim(folio); remove: mtree_erase(&ghvm->mm, gfn); return ret; @@ -207,6 +223,7 @@ static int __gunyah_vm_reclaim_folio_locked(struct gunyah_vm *ghvm, void *entry, { u32 map_flags = BIT(GUNYAH_ADDRSPACE_MAP_FLAG_PARTIAL); struct gunyah_resource *guest_extent, *host_extent, *addrspace; + enum gunyah_pagetable_access access; enum gunyah_error gunyah_error; struct folio *folio; bool write, share; @@ -264,6 +281,24 @@ static int __gunyah_vm_reclaim_folio_locked(struct gunyah_vm *ghvm, void *entry, goto err; } + if (share && write) + access = GUNYAH_PAGETABLE_ACCESS_RW; + else if (share && !write) + access = GUNYAH_PAGETABLE_ACCESS_R; + else if (!share && write) + access = GUNYAH_PAGETABLE_ACCESS_RWX; + else /* !share && !write */ + access = GUNYAH_PAGETABLE_ACCESS_RX; + + ret = gunyah_rm_platform_reclaim_demand_page(ghvm->rm, ghvm->vmid, + access, folio); + if (ret) { + pr_err_ratelimited( + "Platform failed to reclaim memory for guest address 0x%016llx: %d", + gunyah_gfn_to_gpa(gfn), ret); + goto err; + } + BUG_ON(mtree_erase(&ghvm->mm, gfn) != entry); if (folio_test_private(folio)) { diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index c23e1a88703e8..cfb80f40d4e4a 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -198,6 +198,57 @@ struct gunyah_rm_mem_parcel { u32 mem_handle; }; +enum gunyah_pagetable_access { + /* clang-format off */ + GUNYAH_PAGETABLE_ACCESS_NONE = 0, + GUNYAH_PAGETABLE_ACCESS_X = 1, + GUNYAH_PAGETABLE_ACCESS_W = 2, + GUNYAH_PAGETABLE_ACCESS_R = 4, + GUNYAH_PAGETABLE_ACCESS_RX = 5, + GUNYAH_PAGETABLE_ACCESS_RW = 6, + GUNYAH_PAGETABLE_ACCESS_RWX = 7, + /* clang-format on */ +}; + +struct gunyah_rm_platform_ops { + int (*pre_mem_share)(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *mem_parcel); + int (*post_mem_reclaim)(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *mem_parcel); + + int (*pre_demand_page)(struct gunyah_rm *rm, u16 vmid, + enum gunyah_pagetable_access access, + struct folio *folio); + int (*release_demand_page)(struct gunyah_rm *rm, u16 vmid, + enum gunyah_pagetable_access access, + struct folio *folio); +}; + +#if IS_ENABLED(CONFIG_GUNYAH_PLATFORM_HOOKS) +int gunyah_rm_register_platform_ops( + const struct gunyah_rm_platform_ops *platform_ops); +void gunyah_rm_unregister_platform_ops( + const struct gunyah_rm_platform_ops *platform_ops); +int devm_gunyah_rm_register_platform_ops( + struct device *dev, const struct gunyah_rm_platform_ops *ops); +#else +static inline int gunyah_rm_register_platform_ops( + const struct gunyah_rm_platform_ops *platform_ops) +{ + return 0; +} +static inline void gunyah_rm_unregister_platform_ops( + const struct gunyah_rm_platform_ops *platform_ops) +{ +} +static inline int +devm_gunyah_rm_register_platform_ops(struct device *dev, + const struct gunyah_rm_platform_ops *ops) +{ + return 0; +} +#endif + /******************************************************************************/ /* Common arch-independent definitions for Gunyah hypercalls */ #define GUNYAH_CAPID_INVAL U64_MAX @@ -318,18 +369,6 @@ enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size, #define GUNYAH_ADDRSPACE_SELF_CAP 0 -enum gunyah_pagetable_access { - /* clang-format off */ - GUNYAH_PAGETABLE_ACCESS_NONE = 0, - GUNYAH_PAGETABLE_ACCESS_X = 1, - GUNYAH_PAGETABLE_ACCESS_W = 2, - GUNYAH_PAGETABLE_ACCESS_R = 4, - GUNYAH_PAGETABLE_ACCESS_RX = 5, - GUNYAH_PAGETABLE_ACCESS_RW = 6, - GUNYAH_PAGETABLE_ACCESS_RWX = 7, - /* clang-format on */ -}; - /* clang-format off */ #define GUNYAH_MEMEXTENT_MAPPING_USER_ACCESS GENMASK_ULL(2, 0) #define GUNYAH_MEMEXTENT_MAPPING_KERNEL_ACCESS GENMASK_ULL(6, 4) From patchwork Thu Feb 22 23:16:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568334 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C6C9C47DD9 for ; Thu, 22 Feb 2024 23:32:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A51136B00CC; Thu, 22 Feb 2024 18:32:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A016F6B00CD; Thu, 22 Feb 2024 18:32:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8531E6B00CE; Thu, 22 Feb 2024 18:32:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6F3FA6B00CC for ; Thu, 22 Feb 2024 18:32:01 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 313D01C1303 for ; Thu, 22 Feb 2024 23:32:01 +0000 (UTC) X-FDA: 81821040042.17.CDC5319 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf30.hostedemail.com (Postfix) with ESMTP id 0603380005 for ; Thu, 22 Feb 2024 23:31:58 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=RI92E9jl; spf=pass (imf30.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708644719; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kvX19e3Ohm/qQMw9kxBOF0A0UYzethrCUoEi5ksVirQ=; b=MDWS52g+dbJYL5076I+fBKVGkcD5Ov9NyAXiZX+xNOwX2wlN/JyDGknreImWm6Q9qIlxI7 3j+aYOT3sjSwEiga7LjhZ3bgIdP/bcSKKObC3Toq5M2elsSzDGXXfKFE6xOcAGZ/7x5wbf bwpJ+eioMQ2IGV/4BEkoAydIiaU2WZk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708644719; a=rsa-sha256; cv=none; b=Djf29DluDdsZHGWXYmw6D7tt/d8Hl3W2o0COiJMj8bdoq6zD1ht6xA9tdWOTLq/joxw0Rt rOkYNgo1HjV9/DSRUZweyQnD04v//Az1WaxAsWozybL9p+H68VySZMkpQ35AYGyU+wbGHG eZr2q8a5AHb2RP10pHRvC7JkDkUertI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=RI92E9jl; spf=pass (imf30.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMKnxf028355; Thu, 22 Feb 2024 23:16:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=kvX19e3Ohm/qQMw9kxBOF0A0UYzethrCUoEi5ksVirQ =; b=RI92E9jl2/w+OzOVO3FrLfK8jMkQVPUF9Cit68C2J7jg1LeJ2H89NsrjRiP MHcZJ1v2JHusYbRrz37b4RTD0jxawMde88McQlS/yWqCDFZUBCfS1I6WpO+m50C9 sfpNL+sDe/l7BgnohpYUlqJyRs4Oz4jdNZeDnpw9P3L8Kau5c2Oie/h5k2xCPLSS urMek2HPwSTCYOvuNBZIoUa4JRkbOyIjGxyW82oAVkwkUwXQpleVbIxM+SXASOJ+ Ldpqsx5DPgbbutFpEgKhbxU4zvyJuqpx4qeiJ3aEX0wpBFL3iBJ36qoDKUiZ9EEV bsbXaLOLiXmj6mFbJVT3YPao2sw== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we97tgf8g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:40 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGd27017508 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:39 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:39 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:45 -0800 Subject: [PATCH v17 22/35] virt: gunyah: Add Qualcomm Gunyah platform ops MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-22-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: UtvzZzBYuHQ2yLUa5GJ10kDpUDECSUak X-Proofpoint-ORIG-GUID: UtvzZzBYuHQ2yLUa5GJ10kDpUDECSUak X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 adultscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: 0603380005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: q8ax681cgepasjwxxeagpnh1obwq36cj X-HE-Tag: 1708644718-614337 X-HE-Meta: U2FsdGVkX1/yNaK9E97WlrlKF0nScG0KAI7i+UqmoaAkCTQzpVetyGXQDPU4qmiaKnD7Ju8LWezOJEiLCGqxS1VTp1JgijVeKWrjYUMv3+3DMrj6r1TAk3Pbo8jOyg6a9wVO57QWYZ2KW1rPEYNVv1nvrtuUOZOpVM+hEU/0+zTaHVkVBHesT0HPvjq33JNHBrkEv8Ilt8o+GX05riQRQOpDcD0BPIlQJBqrroxCcw0veKDo2FGuV4XjdKzooNgk8DQDzeUzOa+p/oQKhE+dlrQmVRBUO7U4nKU54AAJCyXJnwLzLu5aVNNUwJZwuakaOdvtyLybhIIH+/owAlUJntmT85JuUaMohgHImwcBso/31Be6RHL3CyTTSR33emNUlAcZC1sJ+yFbiuTE3mvj7Kc2GhXoI4ElBf4IWUrf6KGjK2+f2I+WRbq7sr9iVTriDR03e3Xikvdo2w8F80b+dOtzHTnpjwdLnhk6CirQsZul3buAK/X2Hio+wUw0Wz2dHvAhdnoinVeKs1sEuihevyGPeS1irKVxFYouXKkcjuzIA74aRJrDfCd9latEakKhfCkk+cBmNY87wH95RVcc2ObcOasx+YpYoKLCk+1536Piv42lrqgNAMRbisnCsfIFBqfA/ljE+KyAesQcu6eLRMAp9AXszTz6L35Pqdw9/O8Un6YVUjqjn0rTxbHaeymhrYEzMaAzq6b6JCNA44BHWnF+hrN+CZXpQ1vkVlOD87AOeON7sznx1Uq6IkRcDvTXcbs0pm8a/Wk3HHnx80j5kg4IVX7EfoRpjF87jNrM2LbCJyV1GR6IyLkVi3543HyCGCxiYCLQkMm3bT1JM+MM0sUu8ExgYOO22h1yVAWIjVyE9bPcfuO8jJgNKOQDBsrEXk923prSU32oudhnqcHI42ByT13gh/tNXpcFlbdLnJg0BBJeMblcSFBYdjwOjygmw81KJps7gqj+0ds0KJy DOIzQBeo c3gP5bgiONHt0PAxKVDmB098HwalS3zv3nFrybYFcALE1OkC6V7VU+4lDrMDc2TQkqXAEoEfOc+9w5Q+8AjYu/uKWvUYc5pgsbL0L1Vpd3hLmS7ZmmnslTbdUH+3J64vrqWKR8N0Y5OQkNehmbRzzVTiVeDk/kzQ7GoMx0Tq42D7LDp+uLkTqcfzqXIf+Rz4tZwgpIgSQH/YMJcJMtLfse8awqr9zeeUEqLz0dSm402mNmLfx/Fu7RMrVdoqne8JqiYzWg6JYc2uF34JqID1hl93QRFgGX082Iweb3wiQ9DbvyUbtCrFvW+h4ioV6fKHsvhESwDODm3f83TSRtJ93EtTzEA3j+J3OAXZoyJrH5Nx+MuRAiK1TFXmCbyKm27YiK0RFrclUQFJX5bRUOIgyu3n+s72uwCh4ovOkTApLi6aWZy8XoM+DqyzgFQTB6ejveveo6o/1uT40tte7XmzNgPaVUg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Qualcomm platforms have a firmware entity which performs access control to physical pages. Dynamically started Gunyah virtual machines use the QCOM_SCM_RM_MANAGED_VMID for access. Linux thus needs to assign access to the memory used by guest VMs. Gunyah doesn't do this operation for us since it is the current VM (typically VMID_HLOS) delegating the access and not Gunyah itself. Use the Gunyah platform ops to achieve this so that only Qualcomm platforms attempt to make the needed SCM calls. Reviewed-by: Alex Elder Co-developed-by: Prakruthi Deepak Heragu Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman --- drivers/virt/gunyah/Kconfig | 13 +++ drivers/virt/gunyah/Makefile | 1 + drivers/virt/gunyah/gunyah_qcom.c | 220 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig index 23ba523d25dc8..fe2823dc48bac 100644 --- a/drivers/virt/gunyah/Kconfig +++ b/drivers/virt/gunyah/Kconfig @@ -4,6 +4,7 @@ config GUNYAH tristate "Gunyah Virtualization drivers" depends on ARM64 select GUNYAH_PLATFORM_HOOKS + imply GUNYAH_QCOM_PLATFORM if ARCH_QCOM help The Gunyah drivers are the helper interfaces that run in a guest VM such as basic inter-VM IPC and signaling mechanisms, and higher level @@ -14,3 +15,15 @@ config GUNYAH config GUNYAH_PLATFORM_HOOKS tristate + +config GUNYAH_QCOM_PLATFORM + tristate "Support for Gunyah on Qualcomm platforms" + depends on GUNYAH + select GUNYAH_PLATFORM_HOOKS + select QCOM_SCM + help + Enable support for interacting with Gunyah on Qualcomm + platforms. Interaction with Qualcomm firmware requires + extra platform-specific support. + + Say Y/M here to use Gunyah on Qualcomm platforms. diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index ffcde0e0ccfa9..a6c6f29b887a6 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -4,3 +4,4 @@ gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o vm_mgr_mem.o obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o gunyah_vcpu.o obj-$(CONFIG_GUNYAH_PLATFORM_HOOKS) += gunyah_platform_hooks.o +obj-$(CONFIG_GUNYAH_QCOM_PLATFORM) += gunyah_qcom.o diff --git a/drivers/virt/gunyah/gunyah_qcom.c b/drivers/virt/gunyah/gunyah_qcom.c new file mode 100644 index 0000000000000..f2342d51a0184 --- /dev/null +++ b/drivers/virt/gunyah/gunyah_qcom.c @@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define QCOM_SCM_RM_MANAGED_VMID 0x3A +#define QCOM_SCM_MAX_MANAGED_VMID 0x3F + +static int +qcom_scm_gunyah_rm_pre_mem_share(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *mem_parcel) +{ + struct qcom_scm_vmperm *new_perms __free(kfree) = NULL; + u64 src, src_cpy; + int ret = 0, i, n; + u16 vmid; + + new_perms = kcalloc(mem_parcel->n_acl_entries, sizeof(*new_perms), + GFP_KERNEL); + if (!new_perms) + return -ENOMEM; + + for (n = 0; n < mem_parcel->n_acl_entries; n++) { + vmid = le16_to_cpu(mem_parcel->acl_entries[n].vmid); + if (vmid <= QCOM_SCM_MAX_MANAGED_VMID) + new_perms[n].vmid = vmid; + else + new_perms[n].vmid = QCOM_SCM_RM_MANAGED_VMID; + if (mem_parcel->acl_entries[n].perms & GUNYAH_RM_ACL_X) + new_perms[n].perm |= QCOM_SCM_PERM_EXEC; + if (mem_parcel->acl_entries[n].perms & GUNYAH_RM_ACL_W) + new_perms[n].perm |= QCOM_SCM_PERM_WRITE; + if (mem_parcel->acl_entries[n].perms & GUNYAH_RM_ACL_R) + new_perms[n].perm |= QCOM_SCM_PERM_READ; + } + + src = BIT_ULL(QCOM_SCM_VMID_HLOS); + + for (i = 0; i < mem_parcel->n_mem_entries; i++) { + src_cpy = src; + ret = qcom_scm_assign_mem( + le64_to_cpu(mem_parcel->mem_entries[i].phys_addr), + le64_to_cpu(mem_parcel->mem_entries[i].size), &src_cpy, + new_perms, mem_parcel->n_acl_entries); + if (ret) + break; + } + + /* Did it work ok? */ + if (!ret) + return 0; + + src = 0; + for (n = 0; n < mem_parcel->n_acl_entries; n++) { + vmid = le16_to_cpu(mem_parcel->acl_entries[n].vmid); + if (vmid <= QCOM_SCM_MAX_MANAGED_VMID) + src |= BIT_ULL(vmid); + else + src |= BIT_ULL(QCOM_SCM_RM_MANAGED_VMID); + } + + new_perms[0].vmid = QCOM_SCM_VMID_HLOS; + new_perms[0].perm = QCOM_SCM_PERM_EXEC | QCOM_SCM_PERM_WRITE | + QCOM_SCM_PERM_READ; + + for (i--; i >= 0; i--) { + src_cpy = src; + WARN_ON_ONCE(qcom_scm_assign_mem( + le64_to_cpu(mem_parcel->mem_entries[i].phys_addr), + le64_to_cpu(mem_parcel->mem_entries[i].size), &src_cpy, + new_perms, 1)); + } + + return ret; +} + +static int +qcom_scm_gunyah_rm_post_mem_reclaim(struct gunyah_rm *rm, + struct gunyah_rm_mem_parcel *mem_parcel) +{ + struct qcom_scm_vmperm new_perms; + u64 src = 0, src_cpy; + int ret = 0, i, n; + u16 vmid; + + new_perms.vmid = QCOM_SCM_VMID_HLOS; + new_perms.perm = QCOM_SCM_PERM_EXEC | QCOM_SCM_PERM_WRITE | + QCOM_SCM_PERM_READ; + + for (n = 0; n < mem_parcel->n_acl_entries; n++) { + vmid = le16_to_cpu(mem_parcel->acl_entries[n].vmid); + if (vmid <= QCOM_SCM_MAX_MANAGED_VMID) + src |= (1ull << vmid); + else + src |= (1ull << QCOM_SCM_RM_MANAGED_VMID); + } + + for (i = 0; i < mem_parcel->n_mem_entries; i++) { + src_cpy = src; + ret = qcom_scm_assign_mem( + le64_to_cpu(mem_parcel->mem_entries[i].phys_addr), + le64_to_cpu(mem_parcel->mem_entries[i].size), &src_cpy, + &new_perms, 1); + WARN_ON_ONCE(ret); + } + + return ret; +} + +static int +qcom_scm_gunyah_rm_pre_demand_page(struct gunyah_rm *rm, u16 vmid, + enum gunyah_pagetable_access access, + struct folio *folio) +{ + struct qcom_scm_vmperm new_perms[2]; + unsigned int n = 1; + u64 src; + + new_perms[0].vmid = QCOM_SCM_RM_MANAGED_VMID; + new_perms[0].perm = QCOM_SCM_PERM_EXEC | QCOM_SCM_PERM_WRITE | + QCOM_SCM_PERM_READ; + if (access != GUNYAH_PAGETABLE_ACCESS_X && + access != GUNYAH_PAGETABLE_ACCESS_RX && + access != GUNYAH_PAGETABLE_ACCESS_RWX) { + new_perms[1].vmid = QCOM_SCM_VMID_HLOS; + new_perms[1].perm = QCOM_SCM_PERM_EXEC | QCOM_SCM_PERM_WRITE | + QCOM_SCM_PERM_READ; + n++; + } + + src = BIT_ULL(QCOM_SCM_VMID_HLOS); + + return qcom_scm_assign_mem(__pfn_to_phys(folio_pfn(folio)), + folio_size(folio), &src, new_perms, n); +} + +static int +qcom_scm_gunyah_rm_release_demand_page(struct gunyah_rm *rm, u16 vmid, + enum gunyah_pagetable_access access, + struct folio *folio) +{ + struct qcom_scm_vmperm new_perms; + u64 src; + + new_perms.vmid = QCOM_SCM_VMID_HLOS; + new_perms.perm = QCOM_SCM_PERM_EXEC | QCOM_SCM_PERM_WRITE | + QCOM_SCM_PERM_READ; + + src = BIT_ULL(QCOM_SCM_RM_MANAGED_VMID); + + if (access != GUNYAH_PAGETABLE_ACCESS_X && + access != GUNYAH_PAGETABLE_ACCESS_RX && + access != GUNYAH_PAGETABLE_ACCESS_RWX) + src |= BIT_ULL(QCOM_SCM_VMID_HLOS); + + return qcom_scm_assign_mem(__pfn_to_phys(folio_pfn(folio)), + folio_size(folio), &src, &new_perms, 1); +} + +static struct gunyah_rm_platform_ops qcom_scm_gunyah_rm_platform_ops = { + .pre_mem_share = qcom_scm_gunyah_rm_pre_mem_share, + .post_mem_reclaim = qcom_scm_gunyah_rm_post_mem_reclaim, + .pre_demand_page = qcom_scm_gunyah_rm_pre_demand_page, + .release_demand_page = qcom_scm_gunyah_rm_release_demand_page, +}; + +/* {19bd54bd-0b37-571b-946f-609b54539de6} */ +static const uuid_t QCOM_EXT_UUID = UUID_INIT(0x19bd54bd, 0x0b37, 0x571b, 0x94, + 0x6f, 0x60, 0x9b, 0x54, 0x53, + 0x9d, 0xe6); + +#define GUNYAH_QCOM_EXT_CALL_UUID_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_VENDOR_HYP, 0x3f01) + +static bool gunyah_has_qcom_extensions(void) +{ + struct arm_smccc_res res; + uuid_t uuid; + u32 *up; + + arm_smccc_1_1_smc(GUNYAH_QCOM_EXT_CALL_UUID_ID, &res); + + up = (u32 *)&uuid.b[0]; + up[0] = lower_32_bits(res.a0); + up[1] = lower_32_bits(res.a1); + up[2] = lower_32_bits(res.a2); + up[3] = lower_32_bits(res.a3); + + return uuid_equal(&uuid, &QCOM_EXT_UUID); +} + +static int __init qcom_gunyah_platform_hooks_register(void) +{ + if (!gunyah_has_qcom_extensions()) + return -ENODEV; + + pr_info("Enabling Gunyah hooks for Qualcomm platforms.\n"); + + return gunyah_rm_register_platform_ops( + &qcom_scm_gunyah_rm_platform_ops); +} + +static void __exit qcom_gunyah_platform_hooks_unregister(void) +{ + gunyah_rm_unregister_platform_ops(&qcom_scm_gunyah_rm_platform_ops); +} + +module_init(qcom_gunyah_platform_hooks_register); +module_exit(qcom_gunyah_platform_hooks_unregister); +MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Platform Hooks for Gunyah"); +MODULE_LICENSE("GPL"); From patchwork Thu Feb 22 23:16:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 627CEC54798 for ; Thu, 22 Feb 2024 23:17:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D29426B00A0; Thu, 22 Feb 2024 18:16:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C8A0C6B009E; Thu, 22 Feb 2024 18:16:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB7496B00A1; Thu, 22 Feb 2024 18:16:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8A27D6B009E for ; Thu, 22 Feb 2024 18:16:51 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 64ED0121026 for ; Thu, 22 Feb 2024 23:16:51 +0000 (UTC) X-FDA: 81821001822.18.470F795 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf23.hostedemail.com (Postfix) with ESMTP id 400FF140004 for ; Thu, 22 Feb 2024 23:16:49 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=OK1PaOz+; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf23.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643809; a=rsa-sha256; cv=none; b=eB7Ql0ftME5hPjrDaFtp9/5pRYxUs57lKVRR62Rl4u/vQY6W51sGOWzK9HGwBEac2mH5nn cbyiQhw5WH5esIVYfcF4OgPS56mP8JishnKDdTg5K3/tD/RCv2RNxNLLNvudazLbdCYFqS KR1kSj5E/qqasQLgJ8qu8ZQH9HuLhoY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=OK1PaOz+; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf23.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643809; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8v1GY1FYViwr1gDiWHVBc+SJTGgDxddStunlcMOAt7k=; b=F6W5F8E6d62d2tE7aNaI+pU9+LxqfR4pC716Ryy/l2r5Qq9kYBvCsSzdDnePNXEYNc5IEn uCMwbsOq2vTmTY5IPaSFcT2v7DJ8dUpGIN5+y8T38a/6T7KLlm1+UrkVWQYftYYEHxn0yt uv1rF+x298eZCwa8xVsD0CjBgaGWSTs= Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLfvRH024356; Thu, 22 Feb 2024 23:16:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=8v1GY1FYViwr1gDiWHVBc+SJTGgDxddStunlcMOAt7k =; b=OK1PaOz+MYOt1PRQxr21Xpe1Yw0XL18uDDdIztRL7PEuhE3JQ6rNW4ykj/c TFUu4rzEt/UooddD9ZoWY/uReznTMNCQ9FfW3CVVcXiwHEqgXPZe01gKyevWGrRH 75FD3ICt6slF1RYvDh7Pk+EtBthpUJzXhrOvXqpejpi1bJiJa1OUrcWV9XUv1/uF 8mgM3AFhCOuXgzvwi9WSxQ3Z8mZj9Bv2LzMRpJnc60NkZPoyYTuCICfdzHNfM5Ve ar89z0RMjn9napJp36X5ULJ40hxBRzpBpxoTVC29GK7FiVbkaqEROK74OvcLoMLg TLMb7126bakdJar8ZKaTT9RI7WA== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3weedkr5f1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:41 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGeOL017516 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:40 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:39 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:46 -0800 Subject: [PATCH v17 23/35] virt: gunyah: Implement guestmemfd MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-23-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: O6Ak6C4_gppeo900tdBS_Z0_5i7JFG4I X-Proofpoint-GUID: O6Ak6C4_gppeo900tdBS_Z0_5i7JFG4I X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220178 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 400FF140004 X-Stat-Signature: an3pchs1s1i7r4jnqopzkpd5s1kpfnmz X-HE-Tag: 1708643809-116636 X-HE-Meta: U2FsdGVkX18LYdcvFHLOs2WfTkPjvYeFy0ZGFHWcaaTkF9DV4bNKFl1oAAIseW5qtWmKXTOjgXwPAg6t+Yzc2hM04t5uW/XSO5F4z9t94obsAqqe3UkkIJF/w3S/46KRpIRulN8NwV75FjiHVuv8WQ10M+QIaPfoYG3l8oYnp1PnBHxomr9fQ9MSoCSWvhQrWi04JfSCZ3xBp9Hsa+jODDnPrB8f2f0NHFR870aFzeUpipGWA5eU2GpC0N0Chx3YX517qw9jcpNOyYi969UQQZ0j8p8+DMMvYLpFGJPkU0cJpUUmZdWRa2Fy6PRN+fDYVj33DugHbBARLP4YlqDZPDEfgelBjmo4pBUVjJ8R51E5PQrKGpcwiA9bx+lKP8wg8v/WFi2FfRLo21Fp2QdFim31gzcfJf89abVCwA0Eh+dJTMMb3eNtEW8/n/m1J1Fa49qy08Upzc3PE+4sLGhshz/okvNY+vKsYrVaSUQaVfSsVLLQ9tSQztlFmZb5kQPPL0nIQzW4jn/3HQcUBgGwsTsVNQTLacX41J+z97vPEExToXLsnoD1xNJxwK6mZaq24JUf6MbOR0py0qim+7EMMYLnABRXBQd6fgDQsH9xXdTt1OJfKjRmVejvNuoqh1mYpsw1SEoM17jaRKU/ig07+fyu+OF5JSUiHuHSuLjhX93y3zuffdOaJ74ZCINzprAPBdyqVEE3yO1+IdIMqs+Y2GHWOlPbkaeBthtqxrylHhJViKGhxOOU42jhW6cpNGrQdpkhLAPL8CTyB1+eBqyvW4fXlCSR3LiZnBZ3kK9yJt7Wpli3BWxXlSboMvrAwnMOtZKCxzVCG3UMVq/RmvqHyPpiG4VOLVIql42r30E/lc4UCh1/RvL68Jl9VwIv23tdKQEEgHPzo+WkCcfrQMkJbgGNgOqQeB3Vr8qQuLSbYPsExCGI2OQ+ddljC6VfYMvtX9Kz6zvdEHln+czHQjq 5OoQiBU7 UzpQ8OUV6uThFkgGJi0tqLFatlqlV6BeeQUonmZh2nA61xq6LVZLQmkWlAbBSTl9dIH4dQdypL1b0yPvn58Qg4zRWBjZ8yz7XqWMGuPfqkEBiKnXqZqDaTU2ymH1IuZfxG6bjFQYcEuyJnNWC7KvN9L3+oPId+UMS48ebH+31ZhyT7+TUXhTiY5ljewRqktNIVMbQK7mw+7vkJXQxjLC3qr50ynbwP4ucNItva8jL97LAl4bKa2S8gG1FkGniLVp3kVtTfEyNZvcicvIvXn4OtlMbBlLd01xer6ohiXrQ6SrVfdI6/RU3TJWLbusVDqNkllGcgNXcVYFoKb01EtNGMxVIUrDEwJTB66/r/b7bWkfImVxVaNfmRE5WtNYZMb5xfPsrF8oY4kr7MySpWEScsqmbbA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Memory provided to Gunyah virtual machines are provided by a Gunyah guestmemfd. Because memory provided to virtual machines may be unmapped at stage-2 from the host (i.e. in the hypervisor's page tables for the host), special care needs to be taken to ensure that the kernel doesn't have a page mapped when it is lent to the guest. Without this tracking, a kernel panic could be induced by userspace tricking the kernel into accessing guest-private memory. Introduce the basic guestmemfd ops and ioctl. Userspace should be able to access the memory unless it is provided to the guest virtual machine: this is necessary to allow userspace to preload binaries such as the kernel Image prior to running the VM. Subsequent commits will wire up providing the memory to the guest. Signed-off-by: Elliot Berman --- drivers/virt/gunyah/Makefile | 2 +- drivers/virt/gunyah/guest_memfd.c | 276 ++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/vm_mgr.c | 9 ++ drivers/virt/gunyah/vm_mgr.h | 2 + include/uapi/linux/gunyah.h | 19 +++ 5 files changed, 307 insertions(+), 1 deletion(-) diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index a6c6f29b887a6..c4505fce177dd 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o vm_mgr_mem.o +gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o vm_mgr_mem.o guest_memfd.o obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o gunyah_vcpu.o obj-$(CONFIG_GUNYAH_PLATFORM_HOOKS) += gunyah_platform_hooks.o diff --git a/drivers/virt/gunyah/guest_memfd.c b/drivers/virt/gunyah/guest_memfd.c new file mode 100644 index 0000000000000..19c72aa1d0e5e --- /dev/null +++ b/drivers/virt/gunyah/guest_memfd.c @@ -0,0 +1,276 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) "gunyah_guest_mem: " fmt + +#include +#include +#include +#include +#include +#include + +#include + +#include "vm_mgr.h" + +static struct folio *gunyah_gmem_get_huge_folio(struct inode *inode, + pgoff_t index) +{ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + unsigned long huge_index = round_down(index, HPAGE_PMD_NR); + unsigned long flags = (unsigned long)inode->i_private; + struct address_space *mapping = inode->i_mapping; + gfp_t gfp = mapping_gfp_mask(mapping); + struct folio *folio; + + if (!(flags & GHMF_ALLOW_HUGEPAGE)) + return NULL; + + if (filemap_range_has_page(mapping, huge_index << PAGE_SHIFT, + (huge_index + HPAGE_PMD_NR - 1) + << PAGE_SHIFT)) + return NULL; + + folio = filemap_alloc_folio(gfp, HPAGE_PMD_ORDER); + if (!folio) + return NULL; + + if (filemap_add_folio(mapping, folio, huge_index, gfp)) { + folio_put(folio); + return NULL; + } + + return folio; +#else + return NULL; +#endif +} + +static struct folio *gunyah_gmem_get_folio(struct inode *inode, pgoff_t index) +{ + struct folio *folio; + + folio = gunyah_gmem_get_huge_folio(inode, index); + if (!folio) { + folio = filemap_grab_folio(inode->i_mapping, index); + if (IS_ERR_OR_NULL(folio)) + return NULL; + } + + /* + * Use the up-to-date flag to track whether or not the memory has been + * zeroed before being handed off to the guest. There is no backing + * storage for the memory, so the folio will remain up-to-date until + * it's removed. + */ + if (!folio_test_uptodate(folio)) { + unsigned long nr_pages = folio_nr_pages(folio); + unsigned long i; + + for (i = 0; i < nr_pages; i++) + clear_highpage(folio_page(folio, i)); + + folio_mark_uptodate(folio); + } + + /* + * Ignore accessed, referenced, and dirty flags. The memory is + * unevictable and there is no storage to write back to. + */ + return folio; +} + +static vm_fault_t gunyah_gmem_host_fault(struct vm_fault *vmf) +{ + struct folio *folio; + + folio = gunyah_gmem_get_folio(file_inode(vmf->vma->vm_file), + vmf->pgoff); + if (!folio) + return VM_FAULT_SIGBUS; + + vmf->page = folio_file_page(folio, vmf->pgoff); + + return VM_FAULT_LOCKED; +} + +static const struct vm_operations_struct gunyah_gmem_vm_ops = { + .fault = gunyah_gmem_host_fault, +}; + +static int gunyah_gmem_mmap(struct file *file, struct vm_area_struct *vma) +{ + file_accessed(file); + vma->vm_ops = &gunyah_gmem_vm_ops; + return 0; +} + +/** + * gunyah_gmem_punch_hole() - try to reclaim a range of pages + * @inode: guest memfd inode + * @offset: Offset into memfd to start reclaim + * @len: length to reclaim + * + * Will try to unmap from virtual machines any folios covered by + * [offset, offset+len]. If unmapped, then tries to free those folios + * + * Returns - error code if any folio in the range couldn't be freed. + */ +static long gunyah_gmem_punch_hole(struct inode *inode, loff_t offset, + loff_t len) +{ + truncate_inode_pages_range(inode->i_mapping, offset, offset + len - 1); + + return 0; +} + +static long gunyah_gmem_allocate(struct inode *inode, loff_t offset, loff_t len) +{ + struct address_space *mapping = inode->i_mapping; + pgoff_t start, index, end; + int r; + + /* Dedicated guest is immutable by default. */ + if (offset + len > i_size_read(inode)) + return -EINVAL; + + filemap_invalidate_lock_shared(mapping); + + start = offset >> PAGE_SHIFT; + end = (offset + len) >> PAGE_SHIFT; + + r = 0; + for (index = start; index < end;) { + struct folio *folio; + + if (signal_pending(current)) { + r = -EINTR; + break; + } + + folio = gunyah_gmem_get_folio(inode, index); + if (!folio) { + r = -ENOMEM; + break; + } + + index = folio_next_index(folio); + + folio_unlock(folio); + folio_put(folio); + + /* 64-bit only, wrapping the index should be impossible. */ + if (WARN_ON_ONCE(!index)) + break; + + cond_resched(); + } + + filemap_invalidate_unlock_shared(mapping); + + return r; +} + +static long gunyah_gmem_fallocate(struct file *file, int mode, loff_t offset, + loff_t len) +{ + long ret; + + if (!(mode & FALLOC_FL_KEEP_SIZE)) + return -EOPNOTSUPP; + + if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | + FALLOC_FL_ZERO_RANGE)) + return -EOPNOTSUPP; + + if (!PAGE_ALIGNED(offset) || !PAGE_ALIGNED(len)) + return -EINVAL; + + if (mode & FALLOC_FL_PUNCH_HOLE) + ret = gunyah_gmem_punch_hole(file_inode(file), offset, len); + else + ret = gunyah_gmem_allocate(file_inode(file), offset, len); + + if (!ret) + file_modified(file); + return ret; +} + +static int gunyah_gmem_release(struct inode *inode, struct file *file) +{ + return 0; +} + +static const struct file_operations gunyah_gmem_fops = { + .owner = THIS_MODULE, + .llseek = generic_file_llseek, + .mmap = gunyah_gmem_mmap, + .open = generic_file_open, + .fallocate = gunyah_gmem_fallocate, + .release = gunyah_gmem_release, +}; + +static const struct address_space_operations gunyah_gmem_aops = { + .dirty_folio = noop_dirty_folio, + .migrate_folio = migrate_folio, + .error_remove_folio = generic_error_remove_folio, +}; + +int gunyah_guest_mem_create(struct gunyah_create_mem_args *args) +{ + const char *anon_name = "[gh-gmem]"; + unsigned long fd_flags = 0; + struct inode *inode; + struct file *file; + int fd, err; + + if (!PAGE_ALIGNED(args->size)) + return -EINVAL; + + if (args->flags & ~(GHMF_CLOEXEC | GHMF_ALLOW_HUGEPAGE)) + return -EINVAL; + + if (args->flags & GHMF_CLOEXEC) + fd_flags |= O_CLOEXEC; + + fd = get_unused_fd_flags(fd_flags); + if (fd < 0) + return fd; + + /* + * Use the so called "secure" variant, which creates a unique inode + * instead of reusing a single inode. Each guest_memfd instance needs + * its own inode to track the size, flags, etc. + */ + file = anon_inode_create_getfile(anon_name, &gunyah_gmem_fops, NULL, + O_RDWR, NULL); + if (IS_ERR(file)) { + err = PTR_ERR(file); + goto err_fd; + } + + file->f_flags |= O_LARGEFILE; + + inode = file->f_inode; + WARN_ON(file->f_mapping != inode->i_mapping); + + inode->i_private = (void *)(unsigned long)args->flags; + inode->i_mapping->a_ops = &gunyah_gmem_aops; + inode->i_mode |= S_IFREG; + inode->i_size = args->size; + mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER); + mapping_set_large_folios(inode->i_mapping); + mapping_set_unmovable(inode->i_mapping); + /* Unmovable mappings are supposed to be marked unevictable as well. */ + WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping)); + + fd_install(fd, file); + return fd; + +err_fd: + put_unused_fd(fd); + return err; +} diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index 64967a8b72885..238a7a4da554b 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -696,6 +696,15 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, switch (cmd) { case GUNYAH_CREATE_VM: return gunyah_dev_ioctl_create_vm(rm, arg); + case GUNYAH_CREATE_GUEST_MEM: { + struct gunyah_create_mem_args args; + + if (copy_from_user(&args, (const void __user *)arg, + sizeof(args))) + return -EFAULT; + + return gunyah_guest_mem_create(&args); + } default: return -ENOTTY; } diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index a6a4efa4138b7..7ac0dd066991b 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -171,4 +171,6 @@ int gunyah_vm_provide_folio(struct gunyah_vm *ghvm, struct folio *folio, int gunyah_vm_reclaim_folio(struct gunyah_vm *ghvm, u64 gfn, struct folio *folio); int gunyah_vm_reclaim_range(struct gunyah_vm *ghvm, u64 gfn, u64 nr); +int gunyah_guest_mem_create(struct gunyah_create_mem_args *args); + #endif diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index 46f7d3aa61d05..c5f506350364d 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -20,6 +20,25 @@ */ #define GUNYAH_CREATE_VM _IO(GUNYAH_IOCTL_TYPE, 0x0) /* Returns a Gunyah VM fd */ +enum gunyah_mem_flags { + GHMF_CLOEXEC = (1UL << 0), + GHMF_ALLOW_HUGEPAGE = (1UL << 1), +}; + +/** + * struct gunyah_create_mem_args - Description of guest memory to create + * @flags: See GHMF_*. + */ +struct gunyah_create_mem_args { + __u64 flags; + __u64 size; + __u64 reserved[6]; +}; + +#define GUNYAH_CREATE_GUEST_MEM \ + _IOW(GUNYAH_IOCTL_TYPE, 0x8, \ + struct gunyah_create_mem_args) /* Returns a Gunyah memory fd */ + /* * ioctls for gunyah-vm fds (returned by GUNYAH_CREATE_VM) */ From patchwork Thu Feb 22 23:16:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3ED4C54E49 for ; Thu, 22 Feb 2024 23:17:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E0FE6B00A4; Thu, 22 Feb 2024 18:16:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 322966B00A8; Thu, 22 Feb 2024 18:16:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC5596B00A7; Thu, 22 Feb 2024 18:16:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 615936B00A5 for ; Thu, 22 Feb 2024 18:16:53 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3F69016102F for ; Thu, 22 Feb 2024 23:16:53 +0000 (UTC) X-FDA: 81821001906.05.5612951 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf17.hostedemail.com (Postfix) with ESMTP id 4677F4000B for ; Thu, 22 Feb 2024 23:16:51 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=D3nyL8It; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf17.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643811; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=G57zUnnCOipB39Fc9wEKGkJOLsd/qSHJbghSWcnXHxc=; b=E9kY35lCxiBe9im5CCJbzEJ7WMV0DV/liPiwKrHmrbs7qqVtSeyLRcNu3RtOESPw3DPFQX YLtzfPxsOYVQUWKRjWKQrnb/KNffqdpYDOoNW+aelkRFZ5+FGB/GezKl+mqcXb1ySqc/z3 MPl1uXHY27QMUShahWf3VNDDVhPayOY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=D3nyL8It; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf17.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643811; a=rsa-sha256; cv=none; b=1cKoQ9UYewzLFX5AeNf6P+WSlR+lQqGsARar/nRzwUEDs7p1gMdXoTCVqp4eBLmT22iq9e DA8EwgsBgudnWc70d87D7+dd4V0ZngirbVLdz8Tzx1npwUtWsj9JWrAZt5zDCiEZZ7axuh hCxk222kp81hl2gDT50Pg+XIhOztwqY= Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMsnkp019978; Thu, 22 Feb 2024 23:16:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=G57zUnnCOipB39Fc9wEKGkJOLsd/qSHJbghSWcnXHxc =; b=D3nyL8Itw2xoZCX/+zre+aXKl0KxN22GoMcQt9xUQrVYlwScRt1kKIT9KI3 HZ8veKEe6rtor6Dp/FgAYtxZQhlMaaZdpwc+TnEeFTR2s6hUE67ZYutnTraSOa+D LZsSgUwMhCjTHv0y7luiV5g19Rn3biHwDr5p/ekZB1Z8xKER6Cn5SOnkSJpTj9oc fM5fpldh7lnirw9foJ174cKylphcNhGnJTlAnVq4v2g8Sb35vMeBohpQJaXuJjHu Z6rNs8vp7MlrbedZN8aAhbA5pcvCBplXxLUouQc4BuE/5lUFejUaXeIHYLoZx3Yf GAQ/bmc+WcPZ7wb7dL37+nT5RIg== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we3231h1t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:42 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGfvA017522 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:41 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:40 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:47 -0800 Subject: [PATCH v17 24/35] virt: gunyah: Add ioctl to bind guestmem to VMs MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-24-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 9yYiQdUwUCwOBtv2gOezqpIXaV8fZGn_ X-Proofpoint-GUID: 9yYiQdUwUCwOBtv2gOezqpIXaV8fZGn_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 clxscore=1015 suspectscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220178 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 4677F4000B X-Stat-Signature: d4xqy3b94c9u1t19eaa4ieqpmm339hsq X-Rspam-User: X-HE-Tag: 1708643811-458895 X-HE-Meta: U2FsdGVkX19yBO1v4TzcWcBsLnQgghAAUvJhCIWCVAMooXmIagiHlozdS1Yiin+7lTC5he+hyDEBF24RMPo+lyL0y/tsgJnyyD/Zo2buuKXCww70i3558MRTe2lGbWvJxcfvLHz0u1pna3L2TDHls0U2gci7xl9nSM/w4h444aEaDDxZ1TLiLN8BIMXq6khkZjaV7gsBCA6M71rDVXpF7qKrtcAFNKyQQom0ogSCFOgX2NIn7AfFkBqYGVBvdtpObkDONAYY+IqlDmeukZr9WpjnyPQnSQS/GqO5OFWS32ZiLAx2nR8sEgCPEZM75rKFQoxP4eKB0jYnd8bYeGWecG6u6SGimhsKLjA9Nr4wV5MWrBsSUqHTx+FKFGXLtpu3dh8KrvMvyl1jj6AJ/u2yqOL40AyzqJEfIQ/O/cQ9n82lNi4/CUUw4ZtOYHC4pPI+REB1DJs9XeNPE5cWH3YD65bOAAw6v70qGZQ9cZBU0TENq0nF7TvCo/Weyw7mKO25tZGETxYVGAl8rFuZbI2zrITW6r7DJRJ3g8CIbmeDSSDF6VVINoAbL1UqS0kR059uI366I7aPJkt3I5zi3TPuPHFu0NaIYlzvayIXSDhEcOAIFS+YwpqZyGpb/D7J9bjCHHfcMj/TCGTFj7WQGeHkiduLUmYvQ1P+z5UbvmTQdgSpwFez5n/O44UXaX2NjmPhz2cOTBO0C4zmydQ9CDtBWJMqPQcW4iJ+ReH5FwMGZgtKxSaK/EXrvarAA2DUCki0dn0uDeW6MaSylpZxBJlBw3ClqKQAx2rtcig82yoQAyuuwqufM3ByUprkI6R7JurYfV13diIPbqePgmMx7AYhb8ao7TYkyKL8lWj6RYNiROXWHRhUdA0FtZAQdMezlNu/T/CqbC9LtMD2kMPoB4xUAmpBlz88izFSey66RocIJ6+VOI7Gl3Lo3vDEokSNll7oBx/QBEgMqko= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: A maple tree is used to maintain a map from guest address ranges to a guestmemfd that provides the memory for that range of memory for the guest. The mapping of guest address range to guestmemfd is called a binding. Implement an ioctl to add/remove bindings to the virtual machine. The binding determines whether the memory is shared (host retains access) or lent (host loses access). Signed-off-by: Elliot Berman --- drivers/virt/gunyah/guest_memfd.c | 426 +++++++++++++++++++++++++++++++++++++- drivers/virt/gunyah/vm_mgr.c | 20 ++ drivers/virt/gunyah/vm_mgr.h | 9 + include/uapi/linux/gunyah.h | 41 ++++ 4 files changed, 488 insertions(+), 8 deletions(-) diff --git a/drivers/virt/gunyah/guest_memfd.c b/drivers/virt/gunyah/guest_memfd.c index 19c72aa1d0e5e..d6be8bf67d996 100644 --- a/drivers/virt/gunyah/guest_memfd.c +++ b/drivers/virt/gunyah/guest_memfd.c @@ -16,6 +16,51 @@ #include "vm_mgr.h" +/** + * struct gunyah_gmem_binding - Represents a binding of guestmem to a Gunyah VM + * @gfn: Guest address to place acquired folios + * @ghvm: Pointer to Gunyah VM in this binding + * @i_off: offset into the guestmem to grab folios from + * @file: Pointer to guest_memfd + * @i_entry: list entry for inode->i_private_list + * @flags: Access flags for the binding + * @nr: Number of pages covered by this binding + */ +struct gunyah_gmem_binding { + u64 gfn; + struct gunyah_vm *ghvm; + + pgoff_t i_off; + struct file *file; + struct list_head i_entry; + + u32 flags; + unsigned long nr; +}; + +static inline pgoff_t gunyah_gfn_to_off(struct gunyah_gmem_binding *b, u64 gfn) +{ + return gfn - b->gfn + b->i_off; +} + +static inline u64 gunyah_off_to_gfn(struct gunyah_gmem_binding *b, pgoff_t off) +{ + return off - b->i_off + b->gfn; +} + +static inline bool gunyah_guest_mem_is_lend(struct gunyah_vm *ghvm, u32 flags) +{ + u8 access = flags & GUNYAH_MEM_ACCESS_MASK; + + if (access == GUNYAH_MEM_FORCE_LEND) + return true; + else if (access == GUNYAH_MEM_FORCE_SHARE) + return false; + + /* RM requires all VMs to be protected (isolated) */ + return true; +} + static struct folio *gunyah_gmem_get_huge_folio(struct inode *inode, pgoff_t index) { @@ -83,6 +128,38 @@ static struct folio *gunyah_gmem_get_folio(struct inode *inode, pgoff_t index) return folio; } +/** + * gunyah_gmem_launder_folio() - Tries to unmap one folio from virtual machine(s) + * @folio: The folio to unmap + * + * Returns - 0 if the folio has been reclaimed from any virtual machine(s) that + * folio was mapped into. + */ +static int gunyah_gmem_launder_folio(struct folio *folio) +{ + struct address_space *const mapping = folio->mapping; + struct gunyah_gmem_binding *b; + pgoff_t index = folio_index(folio); + int ret = 0; + u64 gfn; + + filemap_invalidate_lock_shared(mapping); + list_for_each_entry(b, &mapping->i_private_list, i_entry) { + /* if the mapping doesn't cover this folio: skip */ + if (b->i_off > index || index > b->i_off + b->nr) + continue; + + gfn = gunyah_off_to_gfn(b, index); + ret = gunyah_vm_reclaim_folio(b->ghvm, gfn, folio); + if (WARN_RATELIMIT(ret, "failed to reclaim gfn: %08llx %d\n", + gfn, ret)) + break; + } + filemap_invalidate_unlock_shared(mapping); + + return ret; +} + static vm_fault_t gunyah_gmem_host_fault(struct vm_fault *vmf) { struct folio *folio; @@ -92,6 +169,15 @@ static vm_fault_t gunyah_gmem_host_fault(struct vm_fault *vmf) if (!folio) return VM_FAULT_SIGBUS; + /* If the folio is lent to a VM, try to reclaim it */ + if (folio_test_private(folio) && gunyah_gmem_launder_folio(folio)) { + folio_unlock(folio); + folio_put(folio); + return VM_FAULT_SIGBUS; + } + /* gunyah_gmem_launder_folio should clear the private bit if it returns 0 */ + BUG_ON(folio_test_private(folio)); + vmf->page = folio_file_page(folio, vmf->pgoff); return VM_FAULT_LOCKED; @@ -103,9 +189,48 @@ static const struct vm_operations_struct gunyah_gmem_vm_ops = { static int gunyah_gmem_mmap(struct file *file, struct vm_area_struct *vma) { - file_accessed(file); - vma->vm_ops = &gunyah_gmem_vm_ops; - return 0; + struct address_space *const mapping = file->f_mapping; + struct gunyah_gmem_binding *b; + pgoff_t end_off; + int ret = 0; + u64 gfn, nr; + + /* No support for private mappings to avoid COW. */ + if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) != + (VM_SHARED | VM_MAYSHARE)) { + return -EINVAL; + } + + filemap_invalidate_lock_shared(mapping); + /** + * userspace can only mmap if the folios covered by the requested + * offset are not lent to the guest + */ + list_for_each_entry(b, &mapping->i_private_list, i_entry) { + if (!gunyah_guest_mem_is_lend(b->ghvm, b->flags)) + continue; + + /* if the binding doesn't cover this vma: skip */ + if (vma->vm_pgoff + vma_pages(vma) < b->i_off) + continue; + if (vma->vm_pgoff > b->i_off + b->nr) + continue; + + gfn = gunyah_off_to_gfn(b, vma->vm_pgoff); + end_off = max(vma->vm_pgoff + vma_pages(vma), b->i_off + b->nr); + nr = gunyah_off_to_gfn(b, end_off) - gfn; + ret = gunyah_vm_reclaim_range(b->ghvm, gfn, nr); + if (ret) + break; + } + filemap_invalidate_unlock_shared(mapping); + + if (!ret) { + file_accessed(file); + vma->vm_ops = &gunyah_gmem_vm_ops; + } + + return ret; } /** @@ -122,9 +247,7 @@ static int gunyah_gmem_mmap(struct file *file, struct vm_area_struct *vma) static long gunyah_gmem_punch_hole(struct inode *inode, loff_t offset, loff_t len) { - truncate_inode_pages_range(inode->i_mapping, offset, offset + len - 1); - - return 0; + return invalidate_inode_pages2_range(inode->i_mapping, offset, offset + len - 1); } static long gunyah_gmem_allocate(struct inode *inode, loff_t offset, loff_t len) @@ -201,6 +324,12 @@ static long gunyah_gmem_fallocate(struct file *file, int mode, loff_t offset, static int gunyah_gmem_release(struct inode *inode, struct file *file) { + /** + * each binding increments refcount on file, so we shouldn't be here + * if i_private_list not empty. + */ + BUG_ON(!list_empty(&inode->i_mapping->i_private_list)); + return 0; } @@ -213,10 +342,26 @@ static const struct file_operations gunyah_gmem_fops = { .release = gunyah_gmem_release, }; +static bool gunyah_gmem_release_folio(struct folio *folio, gfp_t gfp_flags) +{ + /* should return true if released; launder folio returns 0 if freed */ + return !gunyah_gmem_launder_folio(folio); +} + +static int gunyah_gmem_remove_folio(struct address_space *mapping, + struct folio *folio) +{ + if (mapping != folio->mapping) + return -EINVAL; + + return gunyah_gmem_launder_folio(folio); +} + static const struct address_space_operations gunyah_gmem_aops = { .dirty_folio = noop_dirty_folio, - .migrate_folio = migrate_folio, - .error_remove_folio = generic_error_remove_folio, + .release_folio = gunyah_gmem_release_folio, + .launder_folio = gunyah_gmem_launder_folio, + .error_remove_folio = gunyah_gmem_remove_folio, }; int gunyah_guest_mem_create(struct gunyah_create_mem_args *args) @@ -264,6 +409,7 @@ int gunyah_guest_mem_create(struct gunyah_create_mem_args *args) mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER); mapping_set_large_folios(inode->i_mapping); mapping_set_unmovable(inode->i_mapping); + mapping_set_release_always(inode->i_mapping); /* Unmovable mappings are supposed to be marked unevictable as well. */ WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping)); @@ -274,3 +420,267 @@ int gunyah_guest_mem_create(struct gunyah_create_mem_args *args) put_unused_fd(fd); return err; } + +void gunyah_gmem_remove_binding(struct gunyah_gmem_binding *b) +{ + WARN_ON(gunyah_vm_reclaim_range(b->ghvm, b->gfn, b->nr)); + mtree_erase(&b->ghvm->bindings, b->gfn); + list_del(&b->i_entry); + fput(b->file); + kfree(b); +} + +static inline unsigned long gunyah_gmem_page_mask(struct file *file) +{ + unsigned long gmem_flags = (unsigned long)file_inode(file)->i_private; + + if (gmem_flags & GHMF_ALLOW_HUGEPAGE) { +#if IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) + return HPAGE_PMD_MASK; +#else + return ULONG_MAX; +#endif + } + + return PAGE_MASK; +} + +static int gunyah_gmem_init_binding(struct gunyah_vm *ghvm, struct file *file, + struct gunyah_map_mem_args *args, + struct gunyah_gmem_binding *binding) +{ + const unsigned long page_mask = ~gunyah_gmem_page_mask(file); + + if (args->flags & ~(GUNYAH_MEM_ALLOW_RWX | GUNYAH_MEM_ACCESS_MASK)) + return -EINVAL; + + if (args->guest_addr & page_mask) + return -EINVAL; + + if (args->offset & page_mask) + return -EINVAL; + + if (args->size & page_mask) + return -EINVAL; + + binding->gfn = gunyah_gpa_to_gfn(args->guest_addr); + binding->ghvm = ghvm; + binding->i_off = args->offset >> PAGE_SHIFT; + binding->file = file; + binding->flags = args->flags; + binding->nr = args->size >> PAGE_SHIFT; + + return 0; +} + +static int gunyah_gmem_trim_binding(struct gunyah_gmem_binding *b, + unsigned long start_delta, + unsigned long end_delta) +{ + struct gunyah_vm *ghvm = b->ghvm; + int ret; + + down_write(&ghvm->bindings_lock); + if (!start_delta && !end_delta) { + ret = gunyah_vm_reclaim_range(ghvm, b->gfn, b->nr); + if (ret) + goto unlock; + gunyah_gmem_remove_binding(b); + } else if (start_delta && !end_delta) { + /* keep the start */ + ret = gunyah_vm_reclaim_range(ghvm, b->gfn + start_delta, + b->gfn + b->nr); + if (ret) + goto unlock; + mtree_erase(&ghvm->bindings, b->gfn); + b->nr = start_delta; + ret = mtree_insert_range(&ghvm->bindings, b->gfn, + b->gfn + b->nr - 1, b, GFP_KERNEL); + } else if (!start_delta && end_delta) { + /* keep the end */ + ret = gunyah_vm_reclaim_range(ghvm, b->gfn, + b->gfn + b->nr - end_delta); + if (ret) + goto unlock; + mtree_erase(&ghvm->bindings, b->gfn); + b->gfn += b->nr - end_delta; + b->i_off += b->nr - end_delta; + b->nr = end_delta; + ret = mtree_insert_range(&ghvm->bindings, b->gfn, + b->gfn + b->nr - 1, b, GFP_KERNEL); + } else { + /* TODO: split the mapping into 2 */ + ret = -EINVAL; + } + +unlock: + up_write(&ghvm->bindings_lock); + return ret; +} + +static int gunyah_gmem_remove_mapping(struct gunyah_vm *ghvm, struct file *file, + struct gunyah_map_mem_args *args) +{ + struct inode *inode = file_inode(file); + struct gunyah_gmem_binding *b = NULL; + unsigned long start_delta, end_delta; + struct gunyah_gmem_binding remove; + int ret; + + ret = gunyah_gmem_init_binding(ghvm, file, args, &remove); + if (ret) + return ret; + + ret = -ENOENT; + filemap_invalidate_lock(inode->i_mapping); + list_for_each_entry(b, &inode->i_mapping->i_private_list, i_entry) { + if (b->ghvm != remove.ghvm || b->flags != remove.flags || + WARN_ON(b->file != remove.file)) + continue; + /** + * Test if the binding to remove is within this binding + * [gfn b nr] + * [gfn remove nr] + */ + if (b->gfn > remove.gfn) + continue; + if (b->gfn + b->nr < remove.gfn + remove.nr) + continue; + + /** + * We found the binding! + * Compute the delta in gfn start and make sure the offset + * into guest memfd matches. + */ + start_delta = remove.gfn - b->gfn; + if (remove.i_off - b->i_off != start_delta) + break; + end_delta = b->gfn + b->nr - remove.gfn - remove.nr; + + ret = gunyah_gmem_trim_binding(b, start_delta, end_delta); + break; + } + + filemap_invalidate_unlock(inode->i_mapping); + return ret; +} + +static bool gunyah_gmem_binding_overlaps(struct gunyah_gmem_binding *a, + struct gunyah_gmem_binding *b) +{ + /* assumes we are operating on the same file, check to be sure */ + BUG_ON(a->file != b->file); + + /** + * Gunyah only guarantees we can share a page with one VM and + * doesn't (currently) allow us to share same page with multiple VMs, + * regardless whether host can also access. + * Gunyah supports, but Linux hasn't implemented mapping same page + * into 2 separate addresses in guest's address space. This doesn't + * seem reasonable today, but we could do it later. + * All this to justify: check that the `a` region doesn't overlap with + * `b` region w.r.t. file offsets. + */ + if (a->i_off + a->nr <= b->i_off) + return false; + if (a->i_off >= b->i_off + b->nr) + return false; + + return true; +} + +static int gunyah_gmem_add_mapping(struct gunyah_vm *ghvm, struct file *file, + struct gunyah_map_mem_args *args) +{ + struct gunyah_gmem_binding *b, *tmp = NULL; + struct inode *inode = file_inode(file); + int ret; + + b = kzalloc(sizeof(*b), GFP_KERNEL); + if (!b) + return -ENOMEM; + + ret = gunyah_gmem_init_binding(ghvm, file, args, b); + if (ret) + return ret; + + /** + * When lending memory, we need to unmap single page from kernel's + * logical map. To do that, we need can_set_direct_map(). + * arm64 doesn't map at page granularity without rodata=full. + */ + if (gunyah_guest_mem_is_lend(ghvm, b->flags) && !can_set_direct_map()) { + kfree(b); + pr_warn_once("Cannot lend memory without rodata=full"); + return -EINVAL; + } + + /** + * First, check that the region of guets memfd user is binding isn't + * already bound to some other guest region. + */ + filemap_invalidate_lock(inode->i_mapping); + list_for_each_entry(tmp, &inode->i_mapping->i_private_list, i_entry) { + if (gunyah_gmem_binding_overlaps(b, tmp)) { + ret = -EEXIST; + goto unlock; + } + } + + /** + * mtree_insert_range will check that user hasn't mapped some other guest + * memfd region to the same addresses. + */ + ret = mtree_insert_range(&ghvm->bindings, b->gfn, b->gfn + b->nr - 1, b, + GFP_KERNEL); + if (ret) + goto unlock; + + list_add(&b->i_entry, &inode->i_mapping->i_private_list); + +unlock: + filemap_invalidate_unlock(inode->i_mapping); + return ret; +} + +int gunyah_gmem_modify_mapping(struct gunyah_vm *ghvm, + struct gunyah_map_mem_args *args) +{ + u8 access = args->flags & GUNYAH_MEM_ACCESS_MASK; + struct file *file; + int ret = -EINVAL; + + file = fget(args->guest_mem_fd); + if (!file) + return -EINVAL; + + if (file->f_op != &gunyah_gmem_fops) + goto err_file; + + if (args->flags & ~(GUNYAH_MEM_ALLOW_RWX | GUNYAH_MEM_UNMAP | GUNYAH_MEM_ACCESS_MASK)) + goto err_file; + + /* VM needs to have some permissions to the memory */ + if (!(args->flags & GUNYAH_MEM_ALLOW_RWX)) + goto err_file; + + if (access != GUNYAH_MEM_DEFAULT_ACCESS && + access != GUNYAH_MEM_FORCE_LEND && access != GUNYAH_MEM_FORCE_SHARE) + goto err_file; + + if (!PAGE_ALIGNED(args->guest_addr) || !PAGE_ALIGNED(args->offset) || + !PAGE_ALIGNED(args->size)) + goto err_file; + + if (args->flags & GUNYAH_MEM_UNMAP) { + args->flags &= ~GUNYAH_MEM_UNMAP; + ret = gunyah_gmem_remove_mapping(ghvm, file, args); + } else { + ret = gunyah_gmem_add_mapping(ghvm, file, args); + } + +err_file: + if (ret) + fput(file); + return ret; +} diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index 238a7a4da554b..43878a39d4714 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -404,6 +404,8 @@ static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) INIT_LIST_HEAD(&ghvm->resource_tickets); mt_init(&ghvm->mm); + mt_init(&ghvm->bindings); + init_rwsem(&ghvm->bindings_lock); ghvm->addrspace_ticket.resource_type = GUNYAH_RESOURCE_TYPE_ADDR_SPACE; ghvm->addrspace_ticket.label = GUNYAH_VM_ADDRSPACE_LABEL; @@ -556,6 +558,14 @@ static long gunyah_vm_ioctl(struct file *filp, unsigned int cmd, r = gunyah_vm_rm_function_instance(ghvm, &f); break; } + case GUNYAH_VM_MAP_MEM: { + struct gunyah_map_mem_args args; + + if (copy_from_user(&args, argp, sizeof(args))) + return -EFAULT; + + return gunyah_gmem_modify_mapping(ghvm, &args); + } default: r = -ENOTTY; break; @@ -573,6 +583,8 @@ EXPORT_SYMBOL_GPL(gunyah_vm_get); static void _gunyah_vm_put(struct kref *kref) { struct gunyah_vm *ghvm = container_of(kref, struct gunyah_vm, kref); + struct gunyah_gmem_binding *b; + unsigned long idx = 0; int ret; /** @@ -584,6 +596,13 @@ static void _gunyah_vm_put(struct kref *kref) gunyah_vm_remove_functions(ghvm); + down_write(&ghvm->bindings_lock); + mt_for_each(&ghvm->bindings, b, idx, ULONG_MAX) { + gunyah_gmem_remove_binding(b); + } + up_write(&ghvm->bindings_lock); + WARN_ON(!mtree_empty(&ghvm->bindings)); + mtree_destroy(&ghvm->bindings); /** * If this fails, we're going to lose the memory for good and is * BUG_ON-worthy, but not unrecoverable (we just lose memory). @@ -615,6 +634,7 @@ static void _gunyah_vm_put(struct kref *kref) /* clang-format on */ } + WARN_ON(!mtree_empty(&ghvm->mm)); mtree_destroy(&ghvm->mm); if (ghvm->vm_status > GUNYAH_RM_VM_STATUS_NO_STATE) { diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index 7ac0dd066991b..d9f101fc52632 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -38,6 +38,9 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, * @mm: A maple tree of all memory that has been mapped to a VM. * Indices are guest frame numbers; entries are either folios or * RM mem parcels + * @bindings: A maple tree of guest memfd bindings. Indices are guest frame + * numbers; entries are &struct gunyah_gmem_binding + * @bindings_lock: For serialization to @bindings * @addrspace_ticket: Resource ticket to the capability for guest VM's * address space * @host_private_extent_ticket: Resource ticket to the capability for our @@ -77,6 +80,8 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, struct gunyah_vm { u16 vmid; struct maple_tree mm; + struct maple_tree bindings; + struct rw_semaphore bindings_lock; struct gunyah_vm_resource_ticket addrspace_ticket, host_private_extent_ticket, host_shared_extent_ticket, guest_private_extent_ticket, guest_shared_extent_ticket; @@ -172,5 +177,9 @@ int gunyah_vm_reclaim_folio(struct gunyah_vm *ghvm, u64 gfn, struct folio *folio int gunyah_vm_reclaim_range(struct gunyah_vm *ghvm, u64 gfn, u64 nr); int gunyah_guest_mem_create(struct gunyah_create_mem_args *args); +int gunyah_gmem_modify_mapping(struct gunyah_vm *ghvm, + struct gunyah_map_mem_args *args); +struct gunyah_gmem_binding; +void gunyah_gmem_remove_binding(struct gunyah_gmem_binding *binding); #endif diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index c5f506350364d..1af4c5ae6bc3e 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -87,6 +87,47 @@ struct gunyah_fn_desc { #define GUNYAH_VM_ADD_FUNCTION _IOW(GUNYAH_IOCTL_TYPE, 0x4, struct gunyah_fn_desc) #define GUNYAH_VM_REMOVE_FUNCTION _IOW(GUNYAH_IOCTL_TYPE, 0x7, struct gunyah_fn_desc) +/** + * enum gunyah_map_flags- Possible flags on &struct gunyah_map_mem_args + * @GUNYAH_MEM_DEFAULT_SHARE: Use default host access for the VM type + * @GUNYAH_MEM_FORCE_LEND: Force unmapping the memory once the guest starts to use + * @GUNYAH_MEM_FORCE_SHARE: Allow host to continue accessing memory when guest starts to use + * @GUNYAH_MEM_ALLOW_READ: Allow guest to read memory + * @GUNYAH_MEM_ALLOW_WRITE: Allow guest to write to the memory + * @GUNYAH_MEM_ALLOW_EXEC: Allow guest to execute instructions in the memory + */ +enum gunyah_map_flags { + GUNYAH_MEM_DEFAULT_ACCESS = 0, + GUNYAH_MEM_FORCE_LEND = 1, + GUNYAH_MEM_FORCE_SHARE = 2, +#define GUNYAH_MEM_ACCESS_MASK 0x7 + + GUNYAH_MEM_ALLOW_READ = 1UL << 4, + GUNYAH_MEM_ALLOW_WRITE = 1UL << 5, + GUNYAH_MEM_ALLOW_EXEC = 1UL << 6, + GUNYAH_MEM_ALLOW_RWX = + (GUNYAH_MEM_ALLOW_READ | GUNYAH_MEM_ALLOW_WRITE | GUNYAH_MEM_ALLOW_EXEC), + + GUNYAH_MEM_UNMAP = 1UL << 8, +}; + +/** + * struct gunyah_map_mem_args - Description to provide guest memory into a VM + * @guest_addr: Location in guest address space to place the memory + * @flags: See &enum gunyah_map_flags. + * @guest_mem_fd: File descriptor created by GUNYAH_CREATE_GUEST_MEM + * @offset: Offset into the guest memory file + */ +struct gunyah_map_mem_args { + __u64 guest_addr; + __u32 flags; + __u32 guest_mem_fd; + __u64 offset; + __u64 size; +}; + +#define GUNYAH_VM_MAP_MEM _IOW(GUNYAH_IOCTL_TYPE, 0x9, struct gunyah_map_mem_args) + /* * ioctls for vCPU fds */ From patchwork Thu Feb 22 23:16:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BEB6C54798 for ; Thu, 22 Feb 2024 23:17:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5F2A6B00A9; Thu, 22 Feb 2024 18:16:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C8A046B00A6; Thu, 22 Feb 2024 18:16:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93A1A6B00A8; Thu, 22 Feb 2024 18:16:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5D8496B00A4 for ; Thu, 22 Feb 2024 18:16:53 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2BF01810AC for ; Thu, 22 Feb 2024 23:16:53 +0000 (UTC) X-FDA: 81821001906.08.62A9B0E Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf10.hostedemail.com (Postfix) with ESMTP id 04EB9C0021 for ; Thu, 22 Feb 2024 23:16:50 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=bqtVg4cA; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf10.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643811; a=rsa-sha256; cv=none; b=2X7eQ0TSeOuemhVpINJ2VAs5x48w66IFjoYpJoTt5WmVKrKnx1xiMhZQrbWlu43eYV0A8I /on0qmQWG3PSUYNh4txH5dw+IeK+YMbqhijHl7lYdN7MixY8q/F4ZfiVHege7L5e310eGG UL09VOl6rmdhqjzWgyhmwow35xeh0hQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=bqtVg4cA; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf10.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643811; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qW7+D6aUt163gja6+AuWxPZ9BT7wrXk9X0wveYo7AB8=; b=Tvi5rpR+OKUG9N2/J4lCoeiFgkzJjmg8CcawhctucpamH7Q7sxFkvsC3FRL/h5g+/lfWSX q0zxVURpnygHoQ0u0lZlHAE3XNLGAaJPXnd0GNC8fszhG6zPXTmf/IyxE9KXFfLqct7I0j GPFeRgD3oUYY2jKR8NSTRn0BdzcBdis= Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMv6BT013527; Thu, 22 Feb 2024 23:16:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=qW7+D6aUt163gja6+AuWxPZ9BT7wrXk9X0wveYo7AB8 =; b=bqtVg4cAMWkrBY9cQ8RCBnFA05Meino7ntJnPD+DlJPOBNVgKp6WI9cQucw B/eaWexCT0CQvw7b/wGnKI8bFW07CARJTtqDHj6O8d9S4yxK7F3ihFxbnHPjjshc DpUnFjntxLj9xssnEFX5J14ME+pN12QAahU29A+upnNizsQy0kyyE7/WY+C/2nAa OnPm1YX5l/EdeSL+ZOxOgtuusT8zMD1nE+HT0AqVJdQgy1CAiHvb9hYbFYZ3zPj4 Gqpi2fPXL9IcbTRfww1hibj/Bzx6NWMRA6kv1FdUK7IbvbHk0ZxML7JifRHVGn7m 0GZ6Fijrm0YkdEB4PXM8bGlGvdw== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we4dq17ss-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:42 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGfBM025633 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:41 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:40 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:48 -0800 Subject: [PATCH v17 25/35] virt: gunyah: guestmem: Initialize RM mem parcels from guestmem MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-25-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: vR1aZuf4fzB2Ai69DQJ86JT63-NanqyJ X-Proofpoint-ORIG-GUID: vR1aZuf4fzB2Ai69DQJ86JT63-NanqyJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 adultscore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 04EB9C0021 X-Stat-Signature: d3usz5dh66oi4jzoehpg31iwtsyei5e5 X-HE-Tag: 1708643810-672175 X-HE-Meta: U2FsdGVkX19vg2/sNNyOH9/9rtQowXmO+GqM+xmTUJbFi+ULqhYFSytD2ep0ijmiMCUp+bKxuTG80XnydiiFgSXqeyMIETwN2wAJ60Q1SOr/CZ4m0kS495nr8c2oz9CzhlJJUl9ngGHs4LrasYxaUGYdAtlYH1Cz/+mdMuECogQToRm9E9MHvViySNR0EiYadDj7KxHToDfy9mwXfHGd2gNWwa6KsFBS1qvczESgf+cPs2Ti3dcEm2DVYMiynpYUDbtXgfDZrvuorg9jU6mj9CbZWZG2Rw8boLEiyVmsoq0gVZqsLlgg/ghwTY02tHu5xH4/1TQ0E9dV6XoxxLodOoyo8xHS40MRQ3H1CD+oZ8Fzado/7SGHJgdq0kPW9DZLWrqH9PGuVKrz4Q3lPCCW8g9KQ0xAvhcJ/J15j2ikOhfEkbvXowC0Ie9GoVck3SY/9sd7hbk8hoB92XgLYM4iULZLnfyPVymNoI6qI4Nt4TVLseUemcJaabgscWzkKQLG8KXNqbe7ix31SjRwgwHeRwrNeuxXz+PwbwJ2MSiQEXyeeKOWNKLD1bVIc9qzZwFgOsJYH+3Q701dxxe24oG64mYEWnTUz81ocgu/lmAAUZxsZT7ksi4l2u61UMSmX1DpwDXYyo56lzaOiLCWtBb+WsddrR8oemjkNlkebA/AOL8FCAscAcOxNNs5QTiQjSWrJkgDeWYpDOogj4EVMJ3fR+3tDYil7rKQA0DZ/2B8rI9kaEn0Zaa2AFIAHEeHqb0/Dh+QDFnTHpggsUApPjKqYKC1VeZPWsNcJWBJz6G2rmJW2CV1uLwHFlHPQyKujPk0ZMLKdmh0hpvezopOMJXabBmEAL3+kYMC56/EZy8ewuaNJD5QMK3S/psAWuF81nPlULcJzSxy12+GFWJZ8NMIuqqEJTwDaY77282FK3tFktPinv9i70oEuzQo5EayqvwLD1T6nqTVeHI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Gunyah Resource Manager sets up a virtual machine based on a device tree which lives in guest memory. Resource manager requires this memory to be provided as a memory parcel for it to read and manipulate. Implement a function to construct a memory parcel from a guestmem binding. Signed-off-by: Elliot Berman --- drivers/virt/gunyah/guest_memfd.c | 207 ++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/vm_mgr.h | 6 ++ 2 files changed, 213 insertions(+) diff --git a/drivers/virt/gunyah/guest_memfd.c b/drivers/virt/gunyah/guest_memfd.c index d6be8bf67d996..0c35ffa616d9c 100644 --- a/drivers/virt/gunyah/guest_memfd.c +++ b/drivers/virt/gunyah/guest_memfd.c @@ -684,3 +684,210 @@ int gunyah_gmem_modify_mapping(struct gunyah_vm *ghvm, fput(file); return ret; } + +int gunyah_gmem_share_parcel(struct gunyah_vm *ghvm, struct gunyah_rm_mem_parcel *parcel, + u64 *gfn, u64 *nr) +{ + struct folio *folio, *prev_folio; + unsigned long nr_entries, i, j, start, end; + struct gunyah_gmem_binding *b; + bool lend; + int ret; + + parcel->mem_handle = GUNYAH_MEM_HANDLE_INVAL; + + if (!*nr) + return -EINVAL; + + down_read(&ghvm->bindings_lock); + b = mtree_load(&ghvm->bindings, *gfn); + if (!b || *gfn > b->gfn + b->nr || *gfn < b->gfn) { + ret = -ENOENT; + goto unlock; + } + + /** + * Generally, indices can be based on gfn, guest_memfd offset, or + * offset into binding. start and end are based on offset into binding. + */ + start = *gfn - b->gfn; + + if (start + *nr > b->nr) { + ret = -ENOENT; + goto unlock; + } + + end = start + *nr; + lend = gunyah_guest_mem_is_lend(ghvm, b->flags); + + /** + * First, calculate the number of physically discontiguous regions + * the parcel covers. Each memory entry corresponds to one folio. + * In future, each memory entry could correspond to contiguous + * folios that are also adjacent in guest_memfd, but parcels + * are only being used for small amounts of memory for now, so + * this optimization is premature. + */ + nr_entries = 0; + prev_folio = NULL; + for (i = start + b->i_off; i < end + b->i_off;) { + folio = gunyah_gmem_get_folio(file_inode(b->file), i); /* A */ + if (!folio) { + ret = -ENOMEM; + goto out; + } + + if (lend) { + /* don't lend a folio that is mapped by host */ + if (!gunyah_folio_lend_safe(folio)) { + folio_unlock(folio); + folio_put(folio); + ret = -EPERM; + goto out; + } + folio_set_private(folio); + } + + nr_entries++; + i = folio_index(folio) + folio_nr_pages(folio); + } + end = i - b->i_off; + + parcel->mem_entries = + kcalloc(nr_entries, sizeof(*parcel->mem_entries), GFP_KERNEL); + if (!parcel->mem_entries) { + ret = -ENOMEM; + goto out; + } + + /** + * Walk through all the folios again, now filling the mem_entries array. + */ + j = 0; + prev_folio = NULL; + for (i = start + b->i_off; i < end + b->i_off; j++) { + folio = filemap_get_folio(file_inode(b->file)->i_mapping, i); /* B */ + if (WARN_ON(IS_ERR(folio))) { + ret = PTR_ERR(folio); + i = end + b->i_off; + goto out; + } + + parcel->mem_entries[j].size = cpu_to_le64(folio_size(folio)); + parcel->mem_entries[j].phys_addr = cpu_to_le64(PFN_PHYS(folio_pfn(folio))); + i = folio_index(folio) + folio_nr_pages(folio); + folio_put(folio); /* B */ + } + BUG_ON(j != nr_entries); + parcel->n_mem_entries = nr_entries; + + if (lend) + parcel->n_acl_entries = 1; + + parcel->acl_entries = kcalloc(parcel->n_acl_entries, + sizeof(*parcel->acl_entries), GFP_KERNEL); + if (!parcel->n_acl_entries) { + ret = -ENOMEM; + goto free_entries; + } + + parcel->acl_entries[0].vmid = cpu_to_le16(ghvm->vmid); + if (b->flags & GUNYAH_MEM_ALLOW_READ) + parcel->acl_entries[0].perms |= GUNYAH_RM_ACL_R; + if (b->flags & GUNYAH_MEM_ALLOW_WRITE) + parcel->acl_entries[0].perms |= GUNYAH_RM_ACL_W; + if (b->flags & GUNYAH_MEM_ALLOW_EXEC) + parcel->acl_entries[0].perms |= GUNYAH_RM_ACL_X; + + if (!lend) { + u16 host_vmid; + + ret = gunyah_rm_get_vmid(ghvm->rm, &host_vmid); + if (ret) + goto free_acl; + + parcel->acl_entries[1].vmid = cpu_to_le16(host_vmid); + parcel->acl_entries[1].perms = GUNYAH_RM_ACL_R | GUNYAH_RM_ACL_W | GUNYAH_RM_ACL_X; + } + + parcel->mem_handle = GUNYAH_MEM_HANDLE_INVAL; + folio = filemap_get_folio(file_inode(b->file)->i_mapping, start); /* C */ + *gfn = folio_index(folio) - b->i_off + b->gfn; + *nr = end - (folio_index(folio) - b->i_off); + folio_put(folio); /* C */ + + ret = gunyah_rm_mem_share(ghvm->rm, parcel); + goto out; +free_acl: + kfree(parcel->acl_entries); + parcel->acl_entries = NULL; +free_entries: + kfree(parcel->mem_entries); + parcel->mem_entries = NULL; + parcel->n_mem_entries = 0; +out: + /* unlock the folios */ + for (j = start + b->i_off; j < i;) { + folio = filemap_get_folio(file_inode(b->file)->i_mapping, j); /* D */ + if (WARN_ON(IS_ERR(folio))) + continue; + j = folio_index(folio) + folio_nr_pages(folio); + folio_unlock(folio); /* A */ + if (ret) { + if (folio_test_private(folio)) { + gunyah_folio_host_reclaim(folio); + folio_clear_private(folio); + } + folio_put(folio); /* A */ + } + folio_put(folio); /* D */ + /* matching folio_put for A is done at + * (1) gunyah_gmem_reclaim_parcel or + * (2) after gunyah_gmem_parcel_to_paged, gunyah_vm_reclaim_folio + */ + } +unlock: + up_read(&ghvm->bindings_lock); + return ret; +} + +int gunyah_gmem_reclaim_parcel(struct gunyah_vm *ghvm, + struct gunyah_rm_mem_parcel *parcel, u64 gfn, + u64 nr) +{ + struct gunyah_rm_mem_entry *entry; + struct folio *folio; + pgoff_t i; + int ret; + + if (parcel->mem_handle != GUNYAH_MEM_HANDLE_INVAL) { + ret = gunyah_rm_mem_reclaim(ghvm->rm, parcel); + if (ret) { + dev_err(ghvm->parent, "Failed to reclaim parcel: %d\n", + ret); + /* We can't reclaim the pages -- hold onto the pages + * forever because we don't know what state the memory + * is in + */ + return ret; + } + parcel->mem_handle = GUNYAH_MEM_HANDLE_INVAL; + + for (i = 0; i < parcel->n_mem_entries; i++) { + entry = &parcel->mem_entries[i]; + + folio = pfn_folio(PHYS_PFN(le64_to_cpu(entry->phys_addr))); + + if (folio_test_private(folio)) + gunyah_folio_host_reclaim(folio); + + folio_clear_private(folio); + folio_put(folio); /* A */ + } + + kfree(parcel->mem_entries); + kfree(parcel->acl_entries); + } + + return 0; +} diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index d9f101fc52632..b6bc66f018b09 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -181,5 +181,11 @@ int gunyah_gmem_modify_mapping(struct gunyah_vm *ghvm, struct gunyah_map_mem_args *args); struct gunyah_gmem_binding; void gunyah_gmem_remove_binding(struct gunyah_gmem_binding *binding); +int gunyah_gmem_share_parcel(struct gunyah_vm *ghvm, + struct gunyah_rm_mem_parcel *parcel, u64 *gfn, + u64 *nr); +int gunyah_gmem_reclaim_parcel(struct gunyah_vm *ghvm, + struct gunyah_rm_mem_parcel *parcel, u64 gfn, + u64 nr); #endif From patchwork Thu Feb 22 23:16:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 747EBC54E4A for ; Thu, 22 Feb 2024 23:17:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 739676B00A5; Thu, 22 Feb 2024 18:16:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BE876B00A7; Thu, 22 Feb 2024 18:16:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D58896B00A5; Thu, 22 Feb 2024 18:16:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 95F0C6B00A4 for ; Thu, 22 Feb 2024 18:16:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 63AB5A177F for ; Thu, 22 Feb 2024 23:16:53 +0000 (UTC) X-FDA: 81821001906.06.1AF91F0 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf19.hostedemail.com (Postfix) with ESMTP id 24CFF1A001B for ; Thu, 22 Feb 2024 23:16:50 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=ESuisxBc; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf19.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643811; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w8rE8S1Pv8IOr8KcghO6tPSQw40M/mDtX+e2e/iQtlM=; b=Osas7tDazmqxgR+ay/yBk4xn6jlwEC4IMItpgxrK+joMdycjc0peIi4Ic4eN6Y2LFuEFwA Wf5Rc9ZQBQRI3Yd0sU2u9mqlsCi1AjIjeSqPVJ1Qvlg6BByKfiQi3C8+A3LWty4Gdfy1BS Z+wfyapezUchUBuOI8MaEM2GBCqXqHs= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=ESuisxBc; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf19.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643811; a=rsa-sha256; cv=none; b=uC7XIh5fYHB6pKD0ylYOLPjdyt0mY8rHGkaB9fFCb6CPq8NnffW9MrqMiAVsjIqinZNDay xuLmC6eF5gVbut3S6kNjKsOiGUvvMAt3OlsVKjJyOON5c2i2TxL48xVgrW73cwGQx4+1xN z0/hiQeVd13ArbUJYbFDfGHNBBdlfVs= Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MM2ID0024414; Thu, 22 Feb 2024 23:16:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=w8rE8S1Pv8IOr8KcghO6tPSQw40M/mDtX+e2e/iQtlM =; b=ESuisxBcPaertvoLFuq93cv0T2QQJrTLj+eldogd3CjopQSs/3778M+gUzS jxj/9CKVTRjdSf6ag9jlFmwJtIF1SQmYE4b9HJyhDGaJ1uExLqIiyhZUMputt8/a wRF7XRlx5bM67l1IsKELORQM9CEU1a3JEldxo8raeT4RWsxEVYFi1Vr94pLebWbd jgRNAU0g4P/nIxpcGJuRfLhssO+P7muGdsxejQ6O/XGVlp1gWfJh/lr48DGSJ8e7 eCjN7nckeH9WmcPhh+zhekA0m90zCVqHCqosS/o8VbBvx7YOaVKaZvXD/PJmDf6D stCWfDyTc+mRoSthKgWXAgMYLMw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we1b0jxsy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:42 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGgO2016070 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:42 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:41 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:49 -0800 Subject: [PATCH v17 26/35] virt: gunyah: Share guest VM dtb configuration to Gunyah MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-26-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: sZnW-kKef_N-x5v7jSsFunG273vEf6tT X-Proofpoint-GUID: sZnW-kKef_N-x5v7jSsFunG273vEf6tT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 24CFF1A001B X-Stat-Signature: ix1c8z5z515moao46upamxdbabf8rnbo X-Rspam-User: X-HE-Tag: 1708643810-296949 X-HE-Meta: U2FsdGVkX18+v1zBudo20FAdsYp9VFnEw7L0r773lFOvwxYL4xvP7qoqSVyzfF1bii19n3trAoali6FpKlvtQEdnvfJKsu3fkUKCy+4YsLlBVJg6zvMuZbiPUHg6FVvxlc/gLdOE1OK5k8PIlvNft4FLdukuRbs12u+35N1dLjdI9xyxcBdTpEg2rpBqve1tfhBTia1/SsK0/FZD8V8clZa4yhPcEg8N/CyJ7k2rmR6iwMElOMWPMK952flEtRRbS7h02shbLJZ+yLe7YSiLFyHhNFJitI/wBiDJFeupeKslu2Dd08ulALp6Y2puMEbts8bdL5QsmjVGucUSSGzy8yNMhU3DS+0KNJ2PxZ1RqC3BRL+6XpvH7/MVBk9NeiK/AWfIpJeeqZSBMvILuQ/RC11TsLXqZpqdAc7RzvfdBizW3lIWUqyK0mGouRKBexMaM2Yb6RBvDT4oirCncfASHq/ojurgirMEr1lRPtXZIrOpzhrYOs6zXyHP8lm5I5mgQ2bV3CDwaT08m9He44WFd7KBikvggi5DtXiLY1sNkXG1vF78nY1KXyM+dD2rTR4CT6DjgAjmgzKoKJuIwL3le+bG/z0cHMLABR2LFr/QR4QZl0rcGJykvqjH2tLIeQFHLhgJdNhxBq3rsTvwcH5+ozorZgIJ7FJOm6AzZnjsZaUQ1fEp8tlUdUhYXxzhjS1yegWjrtj0daUm9B9Ka8Ga8+ogfmGmMFcGJbbguSfxMDnDO+jB5TxJr6nnasgSrAh7nOKF/WH3luU0obA4qIb/Jh0GDbqGgFUBRocVoR4Xc1xhPIfsC3t43kjeYvW57LvQ8iCnp4nYe2U/iyzmn1bmarvKDmMjdKVYbRhmkHTvk8TQ9TW/NmyXW9ZB535tsYJeUoGRhLYxoqPV/fE4L4mzkBgW9oAcvF+R+8SZLTAyL28XEwk5P7CjJqZU+k+aVJC61yggCg36yaxWpRzW8NK chxj6fAB FrA4CqV5YjD3O8xBHK6ODshGuC4CEIIZu7tGMr9AYaeRZKPNHrqt9aP5IqrZauzZL1yGqP1RumQtHKekH8UEdNiE0PMG+d0vkaa6aTlY6W1TfJCMAEgqof7q6aODaZXNYC7iXWOptLoFCGmMg9W9rc8Zv8d4tECAoRUQf62mPgnCx/dUgi2qQ+2HEmDoZLncYFpYiiTML31VHUNWBWjRqY+IKC2QmV4kFKcfzfcCxz7ZO/9r+1q7OBDiTNJY/mJvIVafD21ll7hc1sneVJORjeZ+EoziGppcx3SMkQ5taJPiMP+mbSDhOxDrJefg/NA6UG3eYR7k6BiB8ErvJ+pR8DC/TZjnhBbvGYvybEZ+8e2ie3MgpdEyRbsX5YByTol+FE1hZ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Gunyah Resource Manager sets up a virtual machine based on a device tree which lives in guest memory. Resource manager requires this memory to be provided as a memory parcel for it to read and manipulate. Construct a memory parcel, lend it to the virtual machine, and inform resource manager about the device tree location (the memory parcel ID and offset into the memory parcel). Signed-off-by: Elliot Berman --- drivers/virt/gunyah/vm_mgr.c | 45 ++++++++++++++++++++++++++++++++++++++++++-- drivers/virt/gunyah/vm_mgr.h | 13 ++++++++++++- include/uapi/linux/gunyah.h | 14 ++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index 43878a39d4714..198a99d78c44c 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -452,8 +452,23 @@ static int gunyah_vm_start(struct gunyah_vm *ghvm) ghvm->vmid = ret; ghvm->vm_status = GUNYAH_RM_VM_STATUS_LOAD; - ret = gunyah_rm_vm_configure(ghvm->rm, ghvm->vmid, ghvm->auth, 0, 0, 0, - 0, 0); + ghvm->dtb.parcel_start = ghvm->dtb.config.guest_phys_addr >> PAGE_SHIFT; + ghvm->dtb.parcel_pages = ghvm->dtb.config.size >> PAGE_SHIFT; + ret = gunyah_gmem_share_parcel(ghvm, &ghvm->dtb.parcel, + &ghvm->dtb.parcel_start, + &ghvm->dtb.parcel_pages); + if (ret) { + dev_warn(ghvm->parent, + "Failed to allocate parcel for DTB: %d\n", ret); + goto err; + } + + ret = gunyah_rm_vm_configure(ghvm->rm, ghvm->vmid, ghvm->auth, + ghvm->dtb.parcel.mem_handle, 0, 0, + ghvm->dtb.config.guest_phys_addr - + (ghvm->dtb.parcel_start + << PAGE_SHIFT), + ghvm->dtb.config.size); if (ret) { dev_warn(ghvm->parent, "Failed to configure VM: %d\n", ret); goto err; @@ -536,6 +551,21 @@ static long gunyah_vm_ioctl(struct file *filp, unsigned int cmd, long r; switch (cmd) { + case GUNYAH_VM_SET_DTB_CONFIG: { + struct gunyah_vm_dtb_config dtb_config; + + if (copy_from_user(&dtb_config, argp, sizeof(dtb_config))) + return -EFAULT; + + if (overflows_type(dtb_config.guest_phys_addr + dtb_config.size, + u64)) + return -EOVERFLOW; + + ghvm->dtb.config = dtb_config; + + r = 0; + break; + } case GUNYAH_VM_START: { r = gunyah_vm_ensure_started(ghvm); break; @@ -594,6 +624,17 @@ static void _gunyah_vm_put(struct kref *kref) if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_RUNNING) gunyah_vm_stop(ghvm); + if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_LOAD || + ghvm->vm_status == GUNYAH_RM_VM_STATUS_READY || + ghvm->vm_status == GUNYAH_RM_VM_STATUS_INIT_FAILED) { + ret = gunyah_gmem_reclaim_parcel(ghvm, &ghvm->dtb.parcel, + ghvm->dtb.parcel_start, + ghvm->dtb.parcel_pages); + if (ret) + dev_err(ghvm->parent, + "Failed to reclaim DTB parcel: %d\n", ret); + } + gunyah_vm_remove_functions(ghvm); down_write(&ghvm->bindings_lock); diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index b6bc66f018b09..d8c299e5cf7cc 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -74,6 +74,13 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, * @resource_tickets: List of &struct gunyah_vm_resource_ticket * @auth: Authentication mechanism to be used by resource manager when * launching the VM + * @dtb: For tracking dtb configuration when launching the VM + * @dtb.config: Location of the DTB in the guest memory + * @dtb.parcel_start: Guest frame number where the memory parcel that we lent to + * VM (DTB could start in middle of folio; we lend entire + * folio; parcel_start is start of the folio) + * @dtb.parcel_pages: Number of pages lent for the memory parcel + * @dtb.parcel: Data for resource manager to lend the parcel * * Members are grouped by hot path. */ @@ -103,7 +110,11 @@ struct gunyah_vm { struct device *parent; enum gunyah_rm_vm_auth_mechanism auth; - + struct { + struct gunyah_vm_dtb_config config; + u64 parcel_start, parcel_pages; + struct gunyah_rm_mem_parcel parcel; + } dtb; }; /** diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index 1af4c5ae6bc3e..a89d9bedf3e5d 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -42,6 +42,20 @@ struct gunyah_create_mem_args { /* * ioctls for gunyah-vm fds (returned by GUNYAH_CREATE_VM) */ + +/** + * struct gunyah_vm_dtb_config - Set the location of the VM's devicetree blob + * @guest_phys_addr: Address of the VM's devicetree in guest memory. + * @size: Maximum size of the devicetree including space for overlays. + * Resource manager applies an overlay to the DTB and dtb_size should + * include room for the overlay. A page of memory is typicaly plenty. + */ +struct gunyah_vm_dtb_config { + __u64 guest_phys_addr; + __u64 size; +}; +#define GUNYAH_VM_SET_DTB_CONFIG _IOW(GUNYAH_IOCTL_TYPE, 0x2, struct gunyah_vm_dtb_config) + #define GUNYAH_VM_START _IO(GUNYAH_IOCTL_TYPE, 0x3) /** From patchwork Thu Feb 22 23:16:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C671C47DD9 for ; Thu, 22 Feb 2024 23:17:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84B6E6B00A2; Thu, 22 Feb 2024 18:16:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B1606B00A7; Thu, 22 Feb 2024 18:16:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 425E56B00A3; Thu, 22 Feb 2024 18:16:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2BBAB6B00A1 for ; Thu, 22 Feb 2024 18:16:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0CD9916102F for ; Thu, 22 Feb 2024 23:16:53 +0000 (UTC) X-FDA: 81821001906.06.7CC09C3 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf24.hostedemail.com (Postfix) with ESMTP id BBC1F180025 for ; Thu, 22 Feb 2024 23:16:50 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=HWAtZntv; spf=pass (imf24.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643810; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BuEOFyDcoeCThxuQAKrvGhwyWtW7DRLhCyudyTBCcFA=; b=eMiLkQA9stnEUPAtj+WS90X6FZiZ1RVqLfg4rgqpmBXP6pv8w6ljzXpb+YgpGptAdFqpjt y8yRacScv1bAdex6ukc4Z3pBAB/s+i1j68blsIvIARYar6gLVMC2NBjm8mDs9/xjp2VVxZ eLC0FWxGkY4efTWOYSUmW/OeHY1nNwQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643810; a=rsa-sha256; cv=none; b=HfraIIAM4Bw7+cqNIczOrMyV73Got4cMQd/zG5WzsPJnb4oTzQu+Z3FwU0ozWP68FYivmM 8XD52L3v4L+sXey5PepHomp1q6KhUKRBideJISpQiEPa6L4lyo5oNvRxx5AuAgCX1Eq1nC h3GJUiMs3UJxD87XCe7s8DL9kFixsMc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=HWAtZntv; spf=pass (imf24.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MNEFgc001638; Thu, 22 Feb 2024 23:16:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=BuEOFyDcoeCThxuQAKrvGhwyWtW7DRLhCyudyTBCcFA =; b=HWAtZntvqxz5chWhMypDUNBSYkg+/4PVsA98haVnAi08rpWmpYTf4gG1xfY /8NWoCQ3wzAM5kwljBOxDz0OdTrd+9wcxSMeZt3/ikvG7DRpz3x0LyW3cnjdgNQZ +TqTOg6OQPyG1wmtZO62Z5zsAb6APu1bCwVKNmfT7aVDR4Ya40DdtCznOt33lX8Y PV7xE8qpQBSrUpmhc2nudC2cIV/WYVpGjcQyEP7lRHMinp7MLjL/hlYSoyPh5bx3 ILoUXsdCzgJEjvTqZ3AiKxl0tJQKJYWUrS37C7wpBejvCBg/WMwKDS2iM9oguR7K +oB9CLqCOuZyAtzIqDqcKNi0vQw== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wdvwwbj73-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:43 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGgfU018270 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:42 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:42 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:50 -0800 Subject: [PATCH v17 27/35] gunyah: rsc_mgr: Add RPC to enable demand paging MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-27-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: S8HPNkxOEDjWpTzRV8lNGcyD-Qx9mQEa X-Proofpoint-GUID: S8HPNkxOEDjWpTzRV8lNGcyD-Qx9mQEa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 spamscore=0 impostorscore=0 mlxlogscore=785 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: BBC1F180025 X-Rspam-User: X-Stat-Signature: an8etp3acrg97rz9rwu3yfrtpp1oekt9 X-Rspamd-Server: rspam03 X-HE-Tag: 1708643810-942049 X-HE-Meta: U2FsdGVkX18AyprLnOj+RL4+4Thc/Yx4CVw3mnrQXD8yWQPitbi+rlPT1pDtYMuNMG0si4r6u9t3DrCMvGuY5fcSgOBSZujmabAPQBV53oI9TlHpWV1NPcrLvNhv647cMWvmkVu/+z0yT7iZLo9pIgVixgcSeFLMle5D+DHT5bdk41vDRlamZzl9tC/g045SJew9bMcBKw2M9LFZaQcEriSUE6OI6Y8ExSpfUDE1XAxYZFm0WTsBXZ4nyuht6zi2mhOneyk7JN6EV37FI/1Vz1ZqoRFjR6Aov9p+/3IyEEyYJTcQDfFB8pv+eaGg30/4U06BGJcXM8mOTwCukbGyQBmW4jPDvMo7uT7KvgCPQztRExCswroZ1n3amvOqg6UYknHcQpOGMzgb+o5MJFraiWRnuigPM+TC7/HH5XR9q6C/9iesRTNuuczutf27eYEgkpPouLRuDbU9fBphn/GMb+kPE6bnT0t/TqVo4zCUocBJj4nse2XAQ+3Jnsn5NbtOAEtmBvVpn/Pg2GcMl34biayIBwNSnStjpGqF/X9le/eJ3p3OaiM/KG5koMID8xsRm2dC3g+A3MHGRi04VG9+3ljGho8boHktNN5dwD+ExA2tjp6txPKrn66YpG3qkvLL7D6C/aYBAMBfe0qmJvwqheh2hZheWo5eNErA6Ua1YXx/C3EvZmWatY7+fSq6ibALs6uPFjA2mIH1+xFvMqWguO9DAQG44qdK2p4K6aCWv3Kb3b7yF3bE+Cjw8xciPHjm/Rg9R7tx62I0di6V/FfIdkTVcnJTCXEBj8LdY3w5iyIeKXdY4PhBtwZUD4XW4NRpgeHfr/gUfwMqmL3GSuMGmnA8Z40tAc9w0w8aVFhFg4Nx5LVSf33Hnd2IVuSZHZl8+8cMZk+H9DSvUT2EUSL+uQyxqRXlxL7XY8NyizINQaa6f1V8hs/O51umONeGOv0lF1F514R8rHhospPTggn zWbl8yN2 bDX4SFpFtE0Zv2fyq4P9hdmWj8yLB8kYNkhUUelf6zRxScfxeH8U3G4AK4nVKsqA+duGMB8MUW+i23JpEs3aYFcnT6CV2DqULORyHozWNPSQ7IkYQWEKzbnIrklY7utZfVpgbWnvpgsth9pHofOX106U9bwp7GdklfMRLuptbZ56c1kJUiJ6TPcTaygzFWrlU4EhcAE+x9lG65XwPt8xWN9SA+z0VsD0x8jSthWuwpzHGz6MTuu0QwKDBSF3SRv1KtYqifAktX/VpvyMRq4EbgpKNFa59OIa6gZr0UZIH2zbMGR8lONt9de9YyBLPZZpXzl7VDMUV5y1c1XAMYqthRfGYZV3NWjVws3EjrEqIqi13+8q9TVDYd/HgqsaUQT7nUaO//8z86V74/mxn9xv2prfQeelCv/kST95kb/mwVqTsMc0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add Gunyah Resource Manager RPC to enable demand paging for a virtual machine. Resource manager needs to be informed of private memory regions which will be demand paged and the location where the DTB memory parcel should live in the guest's address space. Signed-off-by: Elliot Berman --- drivers/virt/gunyah/rsc_mgr.h | 12 +++++++ drivers/virt/gunyah/rsc_mgr_rpc.c | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index 68d08d3cff02d..99c2db18579ca 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -108,6 +108,18 @@ int gunyah_rm_get_hyp_resources(struct gunyah_rm *rm, u16 vmid, int gunyah_rm_get_vmid(struct gunyah_rm *rm, u16 *vmid); +int gunyah_rm_vm_set_demand_paging(struct gunyah_rm *rm, u16 vmid, u32 count, + struct gunyah_rm_mem_entry *mem_entries); + +enum gunyah_rm_range_id { + GUNYAH_RM_RANGE_ID_IMAGE = 0, + GUNYAH_RM_RANGE_ID_FIRMWARE = 1, +}; + +int gunyah_rm_vm_set_address_layout(struct gunyah_rm *rm, u16 vmid, + enum gunyah_rm_range_id range_id, + u64 base_address, u64 size); + struct gunyah_resource * gunyah_rm_alloc_resource(struct gunyah_rm *rm, struct gunyah_rm_hyp_resource *hyp_resource); diff --git a/drivers/virt/gunyah/rsc_mgr_rpc.c b/drivers/virt/gunyah/rsc_mgr_rpc.c index 99e5a3f1a5bb9..dfffcf02ddaea 100644 --- a/drivers/virt/gunyah/rsc_mgr_rpc.c +++ b/drivers/virt/gunyah/rsc_mgr_rpc.c @@ -24,6 +24,8 @@ #define GUNYAH_RM_RPC_VM_INIT 0x5600000B #define GUNYAH_RM_RPC_VM_GET_HYP_RESOURCES 0x56000020 #define GUNYAH_RM_RPC_VM_GET_VMID 0x56000024 +#define GUNYAH_RM_RPC_VM_SET_DEMAND_PAGING 0x56000033 +#define GUNYAH_RM_RPC_VM_SET_ADDRESS_LAYOUT 0x56000034 /* clang-format on */ struct gunyah_rm_vm_common_vmid_req { @@ -103,6 +105,23 @@ struct gunyah_rm_vm_config_image_req { __le64 dtb_size; } __packed; +/* Call: VM_SET_DEMAND_PAGING */ +struct gunyah_rm_vm_set_demand_paging_req { + __le16 vmid; + __le16 _padding; + __le32 range_count; + DECLARE_FLEX_ARRAY(struct gunyah_rm_mem_entry, ranges); +} __packed; + +/* Call: VM_SET_ADDRESS_LAYOUT */ +struct gunyah_rm_vm_set_address_layout_req { + __le16 vmid; + __le16 _padding; + __le32 range_id; + __le64 range_base; + __le64 range_size; +} __packed; + /* * Several RM calls take only a VMID as a parameter and give only standard * response back. Deduplicate boilerplate code by using this common call. @@ -494,3 +513,57 @@ int gunyah_rm_get_vmid(struct gunyah_rm *rm, u16 *vmid) return ret; } EXPORT_SYMBOL_GPL(gunyah_rm_get_vmid); + +/** + * gunyah_rm_vm_set_demand_paging() - Enable demand paging of memory regions + * @rm: Handle to a Gunyah resource manager + * @vmid: VMID of the other VM + * @count: Number of demand paged memory regions + * @entries: Array of the regions + */ +int gunyah_rm_vm_set_demand_paging(struct gunyah_rm *rm, u16 vmid, u32 count, + struct gunyah_rm_mem_entry *entries) +{ + struct gunyah_rm_vm_set_demand_paging_req *req __free(kfree) = NULL; + size_t req_size; + + req_size = struct_size(req, ranges, count); + if (req_size == SIZE_MAX) + return -EINVAL; + + req = kzalloc(req_size, GFP_KERNEL); + if (!req) + return -ENOMEM; + + req->vmid = cpu_to_le16(vmid); + req->range_count = cpu_to_le32(count); + memcpy(req->ranges, entries, sizeof(*entries) * count); + + return gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_SET_DEMAND_PAGING, req, + req_size, NULL, NULL); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_set_demand_paging, ERRNO); + +/** + * gunyah_rm_vm_set_address_layout() - Set the start address of images + * @rm: Handle to a Gunyah resource manager + * @vmid: VMID of the other VM + * @range_id: Which image to set + * @base_address: Base address + * @size: Size + */ +int gunyah_rm_vm_set_address_layout(struct gunyah_rm *rm, u16 vmid, + enum gunyah_rm_range_id range_id, + u64 base_address, u64 size) +{ + struct gunyah_rm_vm_set_address_layout_req req = { + .vmid = cpu_to_le16(vmid), + .range_id = cpu_to_le32(range_id), + .range_base = cpu_to_le64(base_address), + .range_size = cpu_to_le64(size), + }; + + return gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_SET_ADDRESS_LAYOUT, &req, + sizeof(req), NULL, NULL); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_set_address_layout, ERRNO); From patchwork Thu Feb 22 23:16:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1326AC54798 for ; Thu, 22 Feb 2024 23:23:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95DC26B00BF; Thu, 22 Feb 2024 18:23:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 90C986B00CA; Thu, 22 Feb 2024 18:23:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75EB76B00CB; Thu, 22 Feb 2024 18:23:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 63A566B00BF for ; Thu, 22 Feb 2024 18:23:24 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 343B4A1786 for ; Thu, 22 Feb 2024 23:23:24 +0000 (UTC) X-FDA: 81821018328.14.5A892D0 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf09.hostedemail.com (Postfix) with ESMTP id 0CCB414002E for ; Thu, 22 Feb 2024 23:23:21 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=A7W7wqej; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf09.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708644202; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vo+GeAkZrIZtCLsV/xLZNLxXgjO/d+8dOj+GwHIQAtA=; b=wL+gUQ9R0OOtEe/22DGGspP9skbdbfaroUKXkWyqrrgR5MaWGpiCjMD+f7+lBLHj8MjWXZ fqVrQVQ4VfO1HW97IOSk7TJWnyU7c0+c9dpVNh3W0fOofpsjelvsXrOW3/DVaz95khU4cV 5Yl4HTbo+tNaQ/1Zbw14TJb1TBEg1Y8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=A7W7wqej; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf09.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708644202; a=rsa-sha256; cv=none; b=k6NN4Xd+UpGFskC2g8CJYAxi7IGg+fzkDtX7qZXoBYRIPWVYi8ZwLspyom6KIS3zEb9aLe NF8yLfFet8tHINhedcvXhhhO6FWTs0vJ9hthhMwq9TMOWHrCD+uPDy09RLKlVGIssoUQrJ WuLGBw4KbWB/D5EC7l6azDAyg1hqrdw= Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMgV2w013376; Thu, 22 Feb 2024 23:16:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=vo+GeAkZrIZtCLsV/xLZNLxXgjO/d+8dOj+GwHIQAtA =; b=A7W7wqejQwx3z1l/oM1GMtburTD6EFddQKuBnKoGYLGt2+b9GKt7z5tgI+G tQHISS7AKjdH4P9r6NEvYcAS1YEnqMEl4l7LBJGz+lBPWzDkqhGp7J00N/ASyFv7 giXzs6CtafrawcvfKE6jMLd5ioTl+Yzaz/N9ZHiNFn7ZA9JkxjWn4vXULo5frsSc 7Vy3gId/qgro/Z87uWkyIb9/gmkAT2Q+Fvi3uvaZvGzBlFUaA/T25boT/q52goHP ub10yfU0ASdLHaWMCuQGHCwxf1FeVtHZ9WkKVYXBGi8CnWC/MwZ0Voeqme+oX/is 6YtjBUgtQxGqEuVVP3Dwrb9DtKA== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wea7csc2y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:43 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGhwg027798 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:43 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:42 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:51 -0800 Subject: [PATCH v17 28/35] virt: gunyah: Enable demand paging MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-28-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: LcPB2YrX8aG6g6aI739ImLk5MugK1jGr X-Proofpoint-GUID: LcPB2YrX8aG6g6aI739ImLk5MugK1jGr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 phishscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0CCB414002E X-Stat-Signature: jwg4ffz9wj17e1dweg1f8wmstum5cats X-HE-Tag: 1708644201-641231 X-HE-Meta: U2FsdGVkX19Y1+SabYGQFvZ5qph19yr1TCkXybexiSrflzn8lwD3QSctj5landzmSVxyO8wamug1y72vNiI9WeX9v4yPx+mQlfKxbYQcR2W3S05IyFa5kPXNJFPz789AjNLoFe6Uh8pxhpXkh2whS63o2CU+lBI5/wlc/jcFY4XaFpJApDZjXaLSn5l9PNqz/2yNnXXoFCHTLuL4Z97PwXFaGOBweLkWS0C4nOwHCHiAb8F62yzzhZQfOuS0yESeqnCvDTTJ/8C4Pvz3h64Smlq93hpU1w/P/AOtTwooeFIgcqnOCjDNUnBWnNZa8Z4INdl6ljIh7MaqJHrbRTfHRGGvjSAKbH0fQk6UWyRswNEwwTBVsg3w/1rPoQFmhctK++wTi533bx4wdDgu9OsBJLM5FoXdh6XCf09nbXUpBneY2D+1RXd4xbJZPc1twIwSXxtJaHwQBPKPPTUxd3IpsB5zWAxNPjeJALiIeYlsg1H1ptBswib7K/4Td0CBF2B2597nuoFQMF5vOINJbG2vjY79uXi/FFa7VVcUfQvW215/MkAWgt31hGpzpPlfxvk07sD5DjBS3sSzMdCzW0twLao4UgdPC6hvXqs/RiTJ1CFbUA4YdBEyipCf/EmxNFMRNJk2O2WHYB53+wjeaEgj97b0HeTRPmIU3fsuWzrfB/5XxxzmxAsz8KP2fmcvLhYZES324y+irwsdZgfA5IsvCmyhotnO2Nl0wHQqqpyDkNQFWVUL/MtK8lAxcXkpGFBkLl8EFjykVBQVTvnGTBerb9byoYZlAYqaSWh00Xd50s6AbkruvOB6JGcBxM2EnApS+mhwBsNRtO/esGRn5C0q0lrbnwcMPVpt8lTIgqmGHpwHCY0esh0EPovTzY3VuBDm/aQwMesRrXdGlBCIx3oOdKcJUPaDoZ/cBFjLLIbffNEAo8RwrTicjipBKz994lvbTETfVv+nJkU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Tell resource manager to enable demand paging and wire vCPU faults to provide the backing folio when a guestmemfd is bound to the faulting access. Signed-off-by: Elliot Berman --- drivers/virt/gunyah/guest_memfd.c | 94 +++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/gunyah_vcpu.c | 41 +++++++++++++---- drivers/virt/gunyah/vm_mgr.c | 29 ++++++++++++ drivers/virt/gunyah/vm_mgr.h | 3 ++ 4 files changed, 159 insertions(+), 8 deletions(-) diff --git a/drivers/virt/gunyah/guest_memfd.c b/drivers/virt/gunyah/guest_memfd.c index 0c35ffa616d9c..797bc29a520bc 100644 --- a/drivers/virt/gunyah/guest_memfd.c +++ b/drivers/virt/gunyah/guest_memfd.c @@ -891,3 +891,97 @@ int gunyah_gmem_reclaim_parcel(struct gunyah_vm *ghvm, return 0; } + +int gunyah_gmem_setup_demand_paging(struct gunyah_vm *ghvm) +{ + struct gunyah_rm_mem_entry *entries; + struct gunyah_gmem_binding *b; + unsigned long index = 0; + u32 count = 0, i; + int ret = 0; + + down_read(&ghvm->bindings_lock); + mt_for_each(&ghvm->bindings, b, index, ULONG_MAX) + if (gunyah_guest_mem_is_lend(ghvm, b->flags)) + count++; + + if (!count) + goto out; + + entries = kcalloc(count, sizeof(*entries), GFP_KERNEL); + if (!entries) { + ret = -ENOMEM; + goto out; + } + + index = i = 0; + mt_for_each(&ghvm->bindings, b, index, ULONG_MAX) { + if (!gunyah_guest_mem_is_lend(ghvm, b->flags)) + continue; + entries[i].phys_addr = cpu_to_le64(gunyah_gfn_to_gpa(b->gfn)); + entries[i].size = cpu_to_le64(b->nr << PAGE_SHIFT); + if (++i == count) + break; + } + + ret = gunyah_rm_vm_set_demand_paging(ghvm->rm, ghvm->vmid, i, entries); + kfree(entries); +out: + up_read(&ghvm->bindings_lock); + return ret; +} + +int gunyah_gmem_demand_page(struct gunyah_vm *ghvm, u64 gpa, bool write) +{ + unsigned long gfn = gunyah_gpa_to_gfn(gpa); + struct gunyah_gmem_binding *b; + struct folio *folio; + int ret; + + down_read(&ghvm->bindings_lock); + b = mtree_load(&ghvm->bindings, gfn); + if (!b) { + ret = -ENOENT; + goto unlock; + } + + if (write && !(b->flags & GUNYAH_MEM_ALLOW_WRITE)) { + ret = -EPERM; + goto unlock; + } + + folio = gunyah_gmem_get_folio(file_inode(b->file), + gunyah_gfn_to_off(b, gfn)); + if (!folio) { + ret = -ENOMEM; + pr_err_ratelimited("Failed to obtain memory for guest addr %016llx\n", gpa); + goto unlock; + } + + /** + * the folio covers the requested guest address, but the folio may not + * start at the requested guest address. recompute the gfn based on the + * folio itself. + */ + gfn = gunyah_off_to_gfn(b, folio_index(folio)); + + filemap_invalidate_lock_shared(b->file->f_mapping); + ret = gunyah_vm_provide_folio(ghvm, folio, gfn, + !gunyah_guest_mem_is_lend(ghvm, b->flags), + !!(b->flags & GUNYAH_MEM_ALLOW_WRITE)); + filemap_invalidate_unlock_shared(b->file->f_mapping); + if (ret) { + if (ret != -EAGAIN) + pr_err_ratelimited( + "Failed to provide folio for guest addr: %016llx: %d\n", + gpa, ret); + goto out; + } +out: + folio_unlock(folio); + folio_put(folio); +unlock: + up_read(&ghvm->bindings_lock); + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_gmem_demand_page); diff --git a/drivers/virt/gunyah/gunyah_vcpu.c b/drivers/virt/gunyah/gunyah_vcpu.c index 8192350f180b0..f8306620b1dd6 100644 --- a/drivers/virt/gunyah/gunyah_vcpu.c +++ b/drivers/virt/gunyah/gunyah_vcpu.c @@ -89,29 +89,44 @@ static irqreturn_t gunyah_vcpu_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static void gunyah_handle_page_fault( +static bool gunyah_handle_page_fault( struct gunyah_vcpu *vcpu, const struct gunyah_hypercall_vcpu_run_resp *vcpu_run_resp) { u64 addr = vcpu_run_resp->state_data[0]; + bool write = !!vcpu_run_resp->state_data[1]; + int ret = 0; + + ret = gunyah_gmem_demand_page(vcpu->ghvm, addr, write); + if (!ret || ret == -EAGAIN) + return true; vcpu->vcpu_run->page_fault.resume_action = GUNYAH_VCPU_RESUME_FAULT; - vcpu->vcpu_run->page_fault.attempt = 0; + vcpu->vcpu_run->page_fault.attempt = ret; vcpu->vcpu_run->page_fault.phys_addr = addr; vcpu->vcpu_run->exit_reason = GUNYAH_VCPU_EXIT_PAGE_FAULT; + return false; } -static void -gunyah_handle_mmio(struct gunyah_vcpu *vcpu, +static bool +gunyah_handle_mmio(struct gunyah_vcpu *vcpu, unsigned long resume_data[3], const struct gunyah_hypercall_vcpu_run_resp *vcpu_run_resp) { u64 addr = vcpu_run_resp->state_data[0], len = vcpu_run_resp->state_data[1], data = vcpu_run_resp->state_data[2]; + int ret; if (WARN_ON(len > sizeof(u64))) len = sizeof(u64); + ret = gunyah_gmem_demand_page(vcpu->ghvm, addr, + vcpu->vcpu_run->mmio.is_write); + if (!ret || ret == -EAGAIN) { + resume_data[1] = GUNYAH_ADDRSPACE_VMMIO_ACTION_RETRY; + return true; + } + if (vcpu_run_resp->state == GUNYAH_VCPU_ADDRSPACE_VMMIO_READ) { vcpu->vcpu_run->mmio.is_write = 0; /* Record that we need to give vCPU user's supplied value next gunyah_vcpu_run() */ @@ -128,11 +143,15 @@ gunyah_handle_mmio(struct gunyah_vcpu *vcpu, vcpu->mmio_addr = vcpu->vcpu_run->mmio.phys_addr = addr; vcpu->vcpu_run->mmio.len = len; vcpu->vcpu_run->exit_reason = GUNYAH_VCPU_EXIT_MMIO; + + return false; } static int gunyah_handle_mmio_resume(struct gunyah_vcpu *vcpu, unsigned long resume_data[3]) { + bool write = vcpu->state == GUNYAH_VCPU_RUN_STATE_MMIO_WRITE; + switch (vcpu->vcpu_run->mmio.resume_action) { case GUNYAH_VCPU_RESUME_HANDLED: if (vcpu->state == GUNYAH_VCPU_RUN_STATE_MMIO_READ) { @@ -148,6 +167,8 @@ static int gunyah_handle_mmio_resume(struct gunyah_vcpu *vcpu, resume_data[1] = GUNYAH_ADDRSPACE_VMMIO_ACTION_FAULT; break; case GUNYAH_VCPU_RESUME_RETRY: + /* userspace probably added a memory binding */ + gunyah_gmem_demand_page(vcpu->ghvm, vcpu->mmio_addr, write); resume_data[1] = GUNYAH_ADDRSPACE_VMMIO_ACTION_RETRY; break; default: @@ -310,11 +331,15 @@ static int gunyah_vcpu_run(struct gunyah_vcpu *vcpu) break; case GUNYAH_VCPU_ADDRSPACE_VMMIO_READ: case GUNYAH_VCPU_ADDRSPACE_VMMIO_WRITE: - gunyah_handle_mmio(vcpu, &vcpu_run_resp); - goto out; + if (!gunyah_handle_mmio(vcpu, resume_data, + &vcpu_run_resp)) + goto out; + break; case GUNYAH_VCPU_ADDRSPACE_PAGE_FAULT: - gunyah_handle_page_fault(vcpu, &vcpu_run_resp); - goto out; + if (!gunyah_handle_page_fault(vcpu, + &vcpu_run_resp)) + goto out; + break; default: pr_warn_ratelimited( "Unknown vCPU state: %llx\n", diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index 198a99d78c44c..473740a1f97d0 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -474,6 +474,23 @@ static int gunyah_vm_start(struct gunyah_vm *ghvm) goto err; } + ret = gunyah_gmem_setup_demand_paging(ghvm); + if (ret) { + dev_warn(ghvm->parent, + "Failed to set up gmem demand paging: %d\n", ret); + goto err; + } + + ret = gunyah_rm_vm_set_address_layout( + ghvm->rm, ghvm->vmid, GUNYAH_RM_RANGE_ID_IMAGE, + ghvm->dtb.parcel_start << PAGE_SHIFT, + ghvm->dtb.parcel_pages << PAGE_SHIFT); + if (ret) { + dev_warn(ghvm->parent, + "Failed to set location of DTB mem parcel: %d\n", ret); + goto err; + } + ret = gunyah_rm_vm_init(ghvm->rm, ghvm->vmid); if (ret) { ghvm->vm_status = GUNYAH_RM_VM_STATUS_INIT_FAILED; @@ -501,8 +518,20 @@ static int gunyah_vm_start(struct gunyah_vm *ghvm) gunyah_vm_add_resource(ghvm, ghrsc); } + ret = gunyah_vm_parcel_to_paged(ghvm, &ghvm->dtb.parcel, + ghvm->dtb.parcel_start, + ghvm->dtb.parcel_pages); + if (ret) + goto err; + ret = gunyah_rm_vm_start(ghvm->rm, ghvm->vmid); if (ret) { + /** + * need to rollback parcel_to_paged because RM is still + * tracking the parcel + */ + gunyah_vm_mm_erase_range(ghvm, ghvm->dtb.parcel_start, + ghvm->dtb.parcel_pages); dev_warn(ghvm->parent, "Failed to start VM: %d\n", ret); goto err; } diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index d8c299e5cf7cc..5eb14f30ba965 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -199,4 +199,7 @@ int gunyah_gmem_reclaim_parcel(struct gunyah_vm *ghvm, struct gunyah_rm_mem_parcel *parcel, u64 gfn, u64 nr); +int gunyah_gmem_setup_demand_paging(struct gunyah_vm *ghvm); +int gunyah_gmem_demand_page(struct gunyah_vm *ghvm, u64 gpa, bool write); + #endif From patchwork Thu Feb 22 23:16:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A90F4C47DD9 for ; Thu, 22 Feb 2024 23:17:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F6836B00A3; Thu, 22 Feb 2024 18:16:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 008B96B00A4; Thu, 22 Feb 2024 18:16:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A47026B00A3; Thu, 22 Feb 2024 18:16:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6F7A76B00A6 for ; Thu, 22 Feb 2024 18:16:53 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4EA31A0E7C for ; Thu, 22 Feb 2024 23:16:53 +0000 (UTC) X-FDA: 81821001906.04.DFC9F34 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf11.hostedemail.com (Postfix) with ESMTP id 601BF40003 for ; Thu, 22 Feb 2024 23:16:51 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=U+sTJqFd; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643811; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UTw6fdMTFcjfZ33gKj3XSf3I7tXoLgizXBMgo1kqPAM=; b=OG9SBxPETJRcOjHvCFj8/BJgreb3bqiLBJHEDTdaamR+jwHqLltQiPVn1u0JFxqy243ZK9 99vkum6C4+2vXCaQmbquFkuVHxPPcgEZUgLzw3XLSl6VbTV/Z6aRnij3vrNcMFHvcnFX5r Zu3ez/pRx3nNhrI/qB2oXlw5uueFbso= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=U+sTJqFd; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643811; a=rsa-sha256; cv=none; b=8ijMqFAD2wlbFyl87nDGocVHqpEd85crrc6iFK+6NlRxREQbsOkr+ZRe0qgHWjHEMFLFlr l9DUu5d4g2CDJ7iTCFeIJkJ2HfIOKPw7jyURCHTuYOKPIxvwBBX15kXob+6vlJZ8uIQ+Dw UvqtfSpq6qvtcWX6DXkIEQZkmZ8G9nw= Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MN1qgD012101; Thu, 22 Feb 2024 23:16:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=UTw6fdMTFcjfZ33gKj3XSf3I7tXoLgizXBMgo1kqPAM =; b=U+sTJqFdPtYFI9+8gqCMOwjh27gzGPcH+qsSLx4MufdlHO9LkEf7qf7ovPi ihfRPS7yIKvuWsNlm79oYxdt5QESg0SMMV3yXcwYzo7h7ZcMU8w4biOvwyEWvKB4 CI2ZJ4GFhKZdQh8y9CD8oNJ0J0Wqqz1k4MYuV98SNyirx3GS+qVM05+9uLuWcM3w GflnMQrs5QyhHqppmshSKwJ2L2hMU4aabmMgWIZRozWCydZu1UuoopYXnqcD6DlG wd/TAz4240tRmK7d9h4d8s/KjIf3MnP3+KjW6Pjag3OKgpn7/8nvxejhmakPxOk0 CSXDQOcslaPX//MjSUXoF0G2RiA== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we97tgf8n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:44 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGhSG017967 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:43 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:43 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:52 -0800 Subject: [PATCH v17 29/35] gunyah: rsc_mgr: Add RPC to set VM boot context MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-29-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: LYAEtq1tGFHE7mfHB6YGiz_72K1Y_peD X-Proofpoint-ORIG-GUID: LYAEtq1tGFHE7mfHB6YGiz_72K1Y_peD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 adultscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: 601BF40003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 5gyui8675967bqy5bru91d1qwsporsbu X-HE-Tag: 1708643811-783139 X-HE-Meta: U2FsdGVkX19VtvIFsnC/jl8xfHnxJYbSOWTYgdD4kWegrXfgGO/kPH4FnYZexZkiYCHPDL4gl7GvPuchTc7wCPH5kLKeh6CCNGUkoppfPK8DBG11fl0VxQnaDSIlOOP5mtzNESFGMYuDHZ0HHm9AkTZ+r7crkRBU6Q57DDUQUqIEAYn80TI8y/r8UAgG4+4ckTCjB+WZ+4cSKSCSIK6GiylaWu0/oboftXoroX4bmTqp4XyxpL9YoTdBQkEdzb4monpEhv8cGMz0GJ729FOuDZJ1tq/6aNmdfck4KiFbaQIxEMzydRvYjCoGU02KJ4fNvLWKmbPqN8K6M3AsqK18LFQCJpRFmXQILYJJd6SOwZudcOK2Ud1ojTJyGIQ/DIFwt2AVrUrMgvfyDqOBSUnq0/6n3Oa19zuxVpI+tdKxD92z+pdg4jgwJYYKgZkRqzgvLrndmIVgx/AKmddD8cUkpLhC7dH4uxH1rRWPwr7Rnrt6Jrm1GWZ3gFaJvyv1JVqf6jLbm7Lf6YHscqoD7j1ksnghWoGiQD6ZLUX/RaBkua+ZQ1/IaaGxVa1H8ImQ6yswSj2azHnSGpXUTCALREEaxNDoZaZCI+PJs47noX8/MW/KZ8tT6RFlfiRA28UbYQwUBDQTaganUcg8W1ImRJUIzjQH8clS9OKpkNXk7C/5D12lEDQ7sC8UByv4Lv6LRgP24xFoe/k4IhfONIhXmx1H7hIDFYRoEPDxZ9yzLbForocFTtjP6QO41/fgezVGjyl3Y5F+31MhSIR7K3jjsf0mchXjU0XO6aA5qFq32M17EzyO0EcRY8/pOgB1rlzA3RvFU0onIHLRPn00Fj68RbK3x4hGT8A94Yl1vRz5PaTZpHmWSplPCwtctjnWlZI6AJk8o6moKl+54954APJZHYQD6wFsSa5Fnd5BzGL+GAdriHGnxhEwxzYIkyphOxaYxwa2j5cNM93xExNmwOfpYU3 Kwcb1CWR 1QEzXYMe34FMoUSHqYJaBx+VMDUzIE20o9iNB X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The initial context of a the primary vCPU can be initialized by performing RM RPC calls. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- drivers/virt/gunyah/rsc_mgr.h | 2 ++ drivers/virt/gunyah/rsc_mgr_rpc.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index 99c2db18579ca..2acaf8dff365e 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -84,6 +84,8 @@ int gunyah_rm_vm_configure(struct gunyah_rm *rm, u16 vmid, u32 mem_handle, u64 image_offset, u64 image_size, u64 dtb_offset, u64 dtb_size); int gunyah_rm_vm_init(struct gunyah_rm *rm, u16 vmid); +int gunyah_rm_vm_set_boot_context(struct gunyah_rm *rm, u16 vmid, u8 reg_set, + u8 reg_index, u64 value); struct gunyah_rm_hyp_resource { u8 type; diff --git a/drivers/virt/gunyah/rsc_mgr_rpc.c b/drivers/virt/gunyah/rsc_mgr_rpc.c index dfffcf02ddaea..eabf8659eb8f9 100644 --- a/drivers/virt/gunyah/rsc_mgr_rpc.c +++ b/drivers/virt/gunyah/rsc_mgr_rpc.c @@ -24,6 +24,7 @@ #define GUNYAH_RM_RPC_VM_INIT 0x5600000B #define GUNYAH_RM_RPC_VM_GET_HYP_RESOURCES 0x56000020 #define GUNYAH_RM_RPC_VM_GET_VMID 0x56000024 +#define GUNYAH_RM_RPC_VM_SET_BOOT_CONTEXT 0x56000031 #define GUNYAH_RM_RPC_VM_SET_DEMAND_PAGING 0x56000033 #define GUNYAH_RM_RPC_VM_SET_ADDRESS_LAYOUT 0x56000034 /* clang-format on */ @@ -105,6 +106,15 @@ struct gunyah_rm_vm_config_image_req { __le64 dtb_size; } __packed; +/* Call: VM_SET_BOOT_CONTEXT */ +struct gunyah_rm_vm_set_boot_context_req { + __le16 vmid; + u8 reg_set; + u8 reg_index; + __le32 _padding; + __le64 value; +} __packed; + /* Call: VM_SET_DEMAND_PAGING */ struct gunyah_rm_vm_set_demand_paging_req { __le16 vmid; @@ -447,6 +457,29 @@ int gunyah_rm_vm_init(struct gunyah_rm *rm, u16 vmid) } ALLOW_ERROR_INJECTION(gunyah_rm_vm_init, ERRNO); +/** + * gunyah_rm_vm_set_boot_context() - set the initial boot context of the primary vCPU + * @rm: Handle to a Gunyah resource manager + * @vmid: VM identifier + * @reg_set: See &enum gunyah_vm_boot_context_reg + * @reg_index: Which register to set; must be 0 for REG_SET_PC + * @value: Value to set in the register + */ +int gunyah_rm_vm_set_boot_context(struct gunyah_rm *rm, u16 vmid, u8 reg_set, + u8 reg_index, u64 value) +{ + struct gunyah_rm_vm_set_boot_context_req req_payload = { + .vmid = cpu_to_le16(vmid), + .reg_set = reg_set, + .reg_index = reg_index, + .value = cpu_to_le64(value), + }; + + return gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_SET_BOOT_CONTEXT, + &req_payload, sizeof(req_payload), NULL, NULL); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_set_boot_context, ERRNO); + /** * gunyah_rm_get_hyp_resources() - Retrieve hypervisor resources (capabilities) associated with a VM * @rm: Handle to a Gunyah resource manager From patchwork Thu Feb 22 23:16:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE0AFC54798 for ; Thu, 22 Feb 2024 23:17:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DA956B00A7; Thu, 22 Feb 2024 18:16:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3182E6B00A6; Thu, 22 Feb 2024 18:16:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11AF26B00AA; Thu, 22 Feb 2024 18:16:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EC73D6B00A6 for ; Thu, 22 Feb 2024 18:16:55 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C5B8C1C0FF3 for ; Thu, 22 Feb 2024 23:16:55 +0000 (UTC) X-FDA: 81821001990.18.CA81B37 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf29.hostedemail.com (Postfix) with ESMTP id C8723120012 for ; Thu, 22 Feb 2024 23:16:53 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=kbFHgLQB; spf=pass (imf29.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643813; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2U+agiqukd/du23WJFcMxZ+WQ4YQxwoiMKt/aEM341M=; b=jKGjfIZsovYZ5zY6v51c6x4h9W/s4feKmw1cEMzKc4qfM7r8cC291d5g/WURCFzz9+SJgd BeaRvM0ivhaTk2Z12OawSS/42yjWPyBo8+YK7Bff7o8CncMcvFJCkeGN4O2kf9I2dnpiCl BUFY/YgWs+I5VlmHfpPXs6HuK+19ueQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=kbFHgLQB; spf=pass (imf29.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643813; a=rsa-sha256; cv=none; b=4XLRWHQCR66saIAb7t+xE/z1Vtn7D74oMXXEt1TEPkEUO8EU/UsY6lWqwGKApvP7Hs3Ynw 0aE7p3LvcbXZQ0ObDxU2bQhrcvM+Crcxup7bnJHlLQ/D7p4mMJo0pNzXwV5R7Nr0LqhBQG xrUcdp7No5CZD2A7bUpVbQC/kM83bpM= Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMwNpl021431; Thu, 22 Feb 2024 23:16:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=2U+agiqukd/du23WJFcMxZ+WQ4YQxwoiMKt/aEM341M =; b=kbFHgLQBLbR00Gsqxu5/yjnO6mhCKRGAewX3RDcewO62JsbY0epB9PFP4W/ 7fBjJfkf6A/5wtJKdZXR5ANSNwdRcY+CKjie411TGFQnDg98zf5i0z8Nd49cJMQ0 hqcT0q/XTYzrBrc9+uqa456+LkslIxpvc2gU/AGequ5tqAQtjf7Ys5Qz6BMbcsJE ertZKrdcYQXHej713oNFG3NJPLfZAUmFWZeL4mbwGQ2l1K8IdUcBT4BCExw2XXmO MHTLw//Jmmt6vYoCRLyYVI7lDj0pZu++CANj0GG6Beq6jYQ73qwdiddRpIoIezMs NXd6NxTzhQtvFWMSSTYwIA7TPnw== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wdw13afvx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:45 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGiQ0025664 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:44 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:43 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:53 -0800 Subject: [PATCH v17 30/35] virt: gunyah: Allow userspace to initialize context of primary vCPU MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-30-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: L2u3zRYMaWfX3RTcPIxtb-zkwxJM5pzM X-Proofpoint-GUID: L2u3zRYMaWfX3RTcPIxtb-zkwxJM5pzM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 malwarescore=0 impostorscore=0 bulkscore=0 adultscore=0 mlxscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 priorityscore=1501 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: C8723120012 X-Rspam-User: X-Stat-Signature: o1i1mj13m471q6y76mid5txbgyw4woam X-Rspamd-Server: rspam01 X-HE-Tag: 1708643813-714110 X-HE-Meta: U2FsdGVkX1/FGDXfWKQkCJiV6HO75McmmMqtDLPT82hE2XToofBOG48HZTVFsl46mx/sBHdszQ+knxDrzT6xiCf2zPWBxKLsi+/o2WMYQffGyknxHFVXMAltRKjAKtS9l3/xQtbFKKFo1VD8pHAGBhHVLOteJhGnUuPuvdWZvX2Sp5QlfX0G/Mk4ZvQprAOeN9sMgMaJbTK6go/2biXUy28/MOAZn4EJOjqmPkHqpuZTBkQ8C3UG1YmQmpwGo3J7ohRT8dECPVCBtHCwDTScC006Do6x93DArK3EolTNJIoxkaAgf1HYphhwlDMXnvJ7BRjPbHFab8p/Uhqmxu5+5ew40nO+p+cc77oP3xPqa9ja1iXzG9qqdgqkqVnoeKRjGrqo+LMnWe4aUsRYua+oPKLro6VrfSjrD5hGH4XN3hmNYAqq06wx+CzyAUdvy3RYOyvA3GqMB9FlMHX4MhOqdiA+I7dDkJ5VUEVXlBJ639skD6Hf+YrJjqb9UiL0BkjpReYeIyM+YGsLylf0gcJiFille4ybAsgE+q+Hh8eO+LHYMBDI4Y6LiGaPPYrkvr6ozvfK504j+ylRehe6mXMINyuR+xchrfNlj6mI41BSqsLwv+7lDLDil4kiMAhdGeaWC2JVH3yUh8F/oISPWqmPK6KrCQEqtNnGwn6Qez6CbMvDu0NnK4pkv8KpHip7HUiFyZyEyALBEEmDbNjxKfx2ySsBAAShuf7WfR5Vz5Yo5RPXuLmcU0WIxqOl45gN23HkaybB5AaCwK3EnsW9546CRgkoHZuxsvArtmuY0m6ynIKmiRMRX2zZ5l1CYzwOTNsqiMNLU/iSpWv6k1K6wndJnS3G0Iy8kUlQl2lWy8gk72/mdUBo4PI1V8ixENFAA+ADe5MWe3LwlVCgc7BSSKjSvFgeSonYtU7/JUas9NwC5GCg7HE7iQur2CDWl7z5CzeNKUMs3BAsp0s= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: RM provides APIs to fill boot context the initial registers upon starting the vCPU. Most importantly, this allows userspace to set the initial PC for the primary vCPU when the VM starts to run. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- drivers/virt/gunyah/vm_mgr.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/vm_mgr.h | 2 ++ include/uapi/linux/gunyah.h | 23 +++++++++++++ 3 files changed, 102 insertions(+) diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index 473740a1f97d0..a61a3f3ae92f1 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -402,6 +402,7 @@ static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) mutex_init(&ghvm->resources_lock); INIT_LIST_HEAD(&ghvm->resources); INIT_LIST_HEAD(&ghvm->resource_tickets); + xa_init(&ghvm->boot_context); mt_init(&ghvm->mm); mt_init(&ghvm->bindings); @@ -427,6 +428,66 @@ static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) return ghvm; } +static long gunyah_vm_set_boot_context(struct gunyah_vm *ghvm, + struct gunyah_vm_boot_context *boot_ctx) +{ + u8 reg_set, reg_index; /* to check values are reasonable */ + int ret; + + reg_set = (boot_ctx->reg >> GUNYAH_VM_BOOT_CONTEXT_REG_SHIFT) & 0xff; + reg_index = boot_ctx->reg & 0xff; + + switch (reg_set) { + case REG_SET_X: + if (reg_index > 31) + return -EINVAL; + break; + case REG_SET_PC: + if (reg_index) + return -EINVAL; + break; + case REG_SET_SP: + if (reg_index > 2) + return -EINVAL; + break; + default: + return -EINVAL; + } + + ret = down_read_interruptible(&ghvm->status_lock); + if (ret) + return ret; + + if (ghvm->vm_status != GUNYAH_RM_VM_STATUS_NO_STATE) { + ret = -EINVAL; + goto out; + } + + ret = xa_err(xa_store(&ghvm->boot_context, boot_ctx->reg, + (void *)boot_ctx->value, GFP_KERNEL)); +out: + up_read(&ghvm->status_lock); + return ret; +} + +static inline int gunyah_vm_fill_boot_context(struct gunyah_vm *ghvm) +{ + unsigned long reg_set, reg_index, id; + void *entry; + int ret; + + xa_for_each(&ghvm->boot_context, id, entry) { + reg_set = (id >> GUNYAH_VM_BOOT_CONTEXT_REG_SHIFT) & 0xff; + reg_index = id & 0xff; + ret = gunyah_rm_vm_set_boot_context( + ghvm->rm, ghvm->vmid, reg_set, reg_index, (u64)entry); + if (ret) + return ret; + } + + return 0; +} + static int gunyah_vm_start(struct gunyah_vm *ghvm) { struct gunyah_rm_hyp_resources *resources; @@ -499,6 +560,13 @@ static int gunyah_vm_start(struct gunyah_vm *ghvm) } ghvm->vm_status = GUNYAH_RM_VM_STATUS_READY; + ret = gunyah_vm_fill_boot_context(ghvm); + if (ret) { + dev_warn(ghvm->parent, "Failed to setup boot context: %d\n", + ret); + goto err; + } + ret = gunyah_rm_get_hyp_resources(ghvm->rm, ghvm->vmid, &resources); if (ret) { dev_warn(ghvm->parent, @@ -625,6 +693,14 @@ static long gunyah_vm_ioctl(struct file *filp, unsigned int cmd, return gunyah_gmem_modify_mapping(ghvm, &args); } + case GUNYAH_VM_SET_BOOT_CONTEXT: { + struct gunyah_vm_boot_context boot_ctx; + + if (copy_from_user(&boot_ctx, argp, sizeof(boot_ctx))) + return -EFAULT; + + return gunyah_vm_set_boot_context(ghvm, &boot_ctx); + } default: r = -ENOTTY; break; @@ -716,6 +792,7 @@ static void _gunyah_vm_put(struct kref *kref) "Failed to deallocate vmid: %d\n", ret); } + xa_destroy(&ghvm->boot_context); gunyah_rm_put(ghvm->rm); kfree(ghvm); } diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index 5eb14f30ba965..8cee93e551700 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -81,6 +81,7 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, * folio; parcel_start is start of the folio) * @dtb.parcel_pages: Number of pages lent for the memory parcel * @dtb.parcel: Data for resource manager to lend the parcel + * @boot_context: Requested initial boot context to set when launching the VM * * Members are grouped by hot path. */ @@ -115,6 +116,7 @@ struct gunyah_vm { u64 parcel_start, parcel_pages; struct gunyah_rm_mem_parcel parcel; } dtb; + struct xarray boot_context; }; /** diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index a89d9bedf3e5d..574116f544722 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -142,6 +142,29 @@ struct gunyah_map_mem_args { #define GUNYAH_VM_MAP_MEM _IOW(GUNYAH_IOCTL_TYPE, 0x9, struct gunyah_map_mem_args) +enum gunyah_vm_boot_context_reg { + REG_SET_X = 0, + REG_SET_PC = 1, + REG_SET_SP = 2, +}; + +#define GUNYAH_VM_BOOT_CONTEXT_REG_SHIFT 8 +#define GUNYAH_VM_BOOT_CONTEXT_REG(reg, idx) (((reg & 0xff) << GUNYAH_VM_BOOT_CONTEXT_REG_SHIFT) |\ + (idx & 0xff)) + +/** + * struct gunyah_vm_boot_context - Set an initial register for the VM + * @reg: Register to set. See GUNYAH_VM_BOOT_CONTEXT_REG_* macros + * @reserved: reserved for alignment + * @value: value to fill in the register + */ +struct gunyah_vm_boot_context { + __u32 reg; + __u32 reserved; + __u64 value; +}; +#define GUNYAH_VM_SET_BOOT_CONTEXT _IOW(GUNYAH_IOCTL_TYPE, 0xa, struct gunyah_vm_boot_context) + /* * ioctls for vCPU fds */ From patchwork Thu Feb 22 23:16:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E6F2C54798 for ; Thu, 22 Feb 2024 23:21:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA5946B00AF; Thu, 22 Feb 2024 18:21:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B55626B00B0; Thu, 22 Feb 2024 18:21:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1CD76B00BC; Thu, 22 Feb 2024 18:21:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8F74B6B00AF for ; Thu, 22 Feb 2024 18:21:35 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 74C4FA160B for ; Thu, 22 Feb 2024 23:21:35 +0000 (UTC) X-FDA: 81821013750.24.2A7A488 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf11.hostedemail.com (Postfix) with ESMTP id 4007F40003 for ; Thu, 22 Feb 2024 23:21:33 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=bhz4VzzK; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708644093; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+zMY+8BLDygCeJCo/brQThGUolvO8zPvVZb2gI6VQ0M=; b=ohAkKlTaJs/5Xq7N//pvGhZGNskKro8Z8Dx+yrG9dcAN453nOncTSR7g/RINF2/i0Z50T4 XZwd7b9Wl/TG+s7kViP+jIBbqsmty1hKEXLG1Ol1x9UP8ntJoKFX/biYAZ9uIQqXV3c7O9 VxLGpUVfuwK3IBSI8rqlcotJ9eJgJcc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=bhz4VzzK; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf11.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708644093; a=rsa-sha256; cv=none; b=0ADOLzaURj49n3G1fgVFAsOmJhiOLzJQEQJVQ6QqW479q47TahaHZoYH4mmIQF0bIBJXTr wF+d0zv4SurFoXRi73NKVFtPZbQjsJCuW96t/YLBd3jGkQtsE8/HrTrtfcqoQmGbe8WkT1 cxAvtfYt4Z6Sl8PFgW1/CSfmEz1DOAA= Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMMRup001705; Thu, 22 Feb 2024 23:16:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=+zMY+8BLDygCeJCo/brQThGUolvO8zPvVZb2gI6VQ0M =; b=bhz4VzzKARL6SdGXSrvf7HpKg2LGXOgzL6K7pg/1mxN6ikdt1uL39LQATj0 qeRJY45qwUsMy4IM1nMQosVq9cnOY28HyN8oA8Dfl1WkIeRbmhAif6KvvxNxveAl JfS6K11kLqnX+FRDlbGQEGWThzEatRazCJD0UiTweKSoTKa80/k815TsTDYbFirX LkvfFbJfDweNNze1UoAgFM4ou1iTP67fPQIbMgkQo/pvGDu3qrvTVYJGEQo+Gq7i ZeTdRO24wOoVTYX2vMHJQPCDl38izLSLuuwasS1cb24yVcGTc8Tx71Iwuv+ewwie gciQeeICaNC4QoOqddVi3iDEr8Q== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we2kf9puu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:46 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGjEm017978 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:45 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:44 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:54 -0800 Subject: [PATCH v17 31/35] virt: gunyah: Add hypercalls for sending doorbell MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-31-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: VZTBPD9GNP7fE8d0d0Q9iN80QKQFlH07 X-Proofpoint-GUID: VZTBPD9GNP7fE8d0d0Q9iN80QKQFlH07 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=0 phishscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=713 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4007F40003 X-Stat-Signature: w4fybtfe39apgq64j5hpeonwubkinm1m X-HE-Tag: 1708644093-148200 X-HE-Meta: U2FsdGVkX19KAcLCuURQpmRKJcofhIzyr9mBqRnnuC7wt+It7XRrql6XdHI+XwoP7flTUpe+Vir1OqhJAZNA/Mh7Bg3w6zCCQ9kw8J1uK/PYsNxygx0DdpbpdTycCD9CDwR8SY3duS4do7F9FMQUFbqdb/vfud9/VnB/iwsrLrz4HUddWXubYxLaP5HPzDXzfvF85BHtKwlhlV1PY/M4xEmrZk0KvKlZwsFUsAWECaa03J0ZR866/fq9cUYyt80rasIiekKdNOW2b86hnruwI9zgTw/cd/ThR72aavY+6s8tXa0uzRz38DNJFVxaYD5AY5p5bebpKrSfksVjKQJGWr27tgqknRP4FU56PPvtnfutLMADsQtFQOHA+CeX/NFpgj85LsdBUaz7LCO08jvoPjRw/TOJUhR//apXqsDZK1ihQTxtNm1N/UodcTFIafpUsQDehki05azDL88LMQ8j64QXXQ3q6uSXfcFka+up+twYZQnMncl9CyJhxsf4U7d0s5+TinmbrHxH4EoEVSNlPyB4b+XVYk15TPJpG4up81pk0kPwQ4KCirq0snUpxZYwoEv1paZWyS0um5IolW4iZSTIuIIlmJjMzaAllOgHfhevVA/9UJfUw6KPTtLzcW7kE+J87SA3kT8kRjJl7QnV8w+LefYBpT2xCJxSIri+k+BvdVnHCih1xbE45QrPPmDvgiJzYGh6bbOPp+MQFPf4O80B6a+xhP722RpQMJJrDIMMrQNNGJHS5g9vHcflivrBDEP1pCQnwZb7ShujxSSNH6p8zUk00c7xUH1PEJp1+npoVwH2twOXVrr/xMLGXZJNArawwyOaZ1mmpxY1sOEbsdMn2vAY9m1TRGEhOA/HLcMlRMTCahK2Tp3MYRS3PMYVh1CQQGrHBQJ3+MGva2GGvs7TcbM7Ocy4oZ7Ikj+fZcYSuIJB25Rp8VZUnMa5aaeMvju2Pwe3pRJgt5fGTS2 fLiTfV6S J8Yri1cVoV4pnbacYGUe4QfsAjTlESe/F9qhq1DVpbsvXgWED6valHqjybAEBNPzuDWrnctQa1lI1bTtr8V8O8t19oScZY2sZpbYipXf+Eu8qcVFNHbEY7YChU3F7UznaiNYK3+fNLOzuuFHMIxsac1gZYkFG1q++xzeRAMb4356WYUq0qj7JVwNKNMkUXJnYsBQp6z4JUBkGg8PeP1L/a/YeFzf+YonXVyFwaq35tWnHw+gPp8Ui3PrPCk5VY5C9eG5I5Owa/IR0jiYsQRT2PCSdEX/m6BiuylYV8S+wCqYXNOGxAGEgI41L0gALEaWswYF77BrwC39c7LcAoL+3Ik++JTXeIdcuhR9dUEuSTEnTK0tyFITTIiQ5z8bVV1jhtN6r2fGdBLKBIjyYWMR89Ws5wkeu8duX4HCm3DqLhxY4ZXkod0Kd8N8sqw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Gunyah doorbells allow a virtual machine to signal another using interrupts. Add the hypercalls needed to assert the interrupt. Reviewed-by: Alex Elder Signed-off-by: Elliot Berman --- arch/arm64/gunyah/gunyah_hypercall.c | 38 ++++++++++++++++++++++++++++++++++++ include/linux/gunyah.h | 5 +++++ 2 files changed, 43 insertions(+) diff --git a/arch/arm64/gunyah/gunyah_hypercall.c b/arch/arm64/gunyah/gunyah_hypercall.c index 38403dc28c66f..3c2672d683ae2 100644 --- a/arch/arm64/gunyah/gunyah_hypercall.c +++ b/arch/arm64/gunyah/gunyah_hypercall.c @@ -37,6 +37,8 @@ EXPORT_SYMBOL_GPL(arch_is_gunyah_guest); /* clang-format off */ #define GUNYAH_HYPERCALL_HYP_IDENTIFY GUNYAH_HYPERCALL(0x8000) +#define GUNYAH_HYPERCALL_BELL_SEND GUNYAH_HYPERCALL(0x8012) +#define GUNYAH_HYPERCALL_BELL_SET_MASK GUNYAH_HYPERCALL(0x8015) #define GUNYAH_HYPERCALL_MSGQ_SEND GUNYAH_HYPERCALL(0x801B) #define GUNYAH_HYPERCALL_MSGQ_RECV GUNYAH_HYPERCALL(0x801C) #define GUNYAH_HYPERCALL_ADDRSPACE_MAP GUNYAH_HYPERCALL(0x802B) @@ -64,6 +66,42 @@ void gunyah_hypercall_hyp_identify( } EXPORT_SYMBOL_GPL(gunyah_hypercall_hyp_identify); +/** + * gunyah_hypercall_bell_send() - Assert a gunyah doorbell + * @capid: capability ID of the doorbell + * @new_flags: bits to set on the doorbell + * @old_flags: Filled with the bits set before the send call if return value is GUNYAH_ERROR_OK + */ +enum gunyah_error gunyah_hypercall_bell_send(u64 capid, u64 new_flags, u64 *old_flags) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GUNYAH_HYPERCALL_BELL_SEND, capid, new_flags, 0, &res); + + if (res.a0 == GUNYAH_ERROR_OK && old_flags) + *old_flags = res.a1; + + return res.a0; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_bell_send); + +/** + * gunyah_hypercall_bell_set_mask() - Set masks on a Gunyah doorbell + * @capid: capability ID of the doorbell + * @enable_mask: which bits trigger the receiver interrupt + * @ack_mask: which bits are automatically acknowledged when the receiver + * interrupt is ack'd + */ +enum gunyah_error gunyah_hypercall_bell_set_mask(u64 capid, u64 enable_mask, u64 ack_mask) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GUNYAH_HYPERCALL_BELL_SET_MASK, capid, enable_mask, ack_mask, 0, &res); + + return res.a0; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_bell_set_mask); + /** * gunyah_hypercall_msgq_send() - Send a buffer on a message queue * @capid: capability ID of the message queue to add message diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index cfb80f40d4e4a..a9d58150de696 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -359,6 +359,11 @@ gunyah_api_version(const struct gunyah_hypercall_hyp_identify_resp *gunyah_api) void gunyah_hypercall_hyp_identify( struct gunyah_hypercall_hyp_identify_resp *hyp_identity); +enum gunyah_error gunyah_hypercall_bell_send(u64 capid, u64 new_flags, + u64 *old_flags); +enum gunyah_error gunyah_hypercall_bell_set_mask(u64 capid, u64 enable_mask, + u64 ack_mask); + /* Immediately raise RX vIRQ on receiver VM */ #define GUNYAH_HYPERCALL_MSGQ_TX_FLAGS_PUSH BIT(0) From patchwork Thu Feb 22 23:16:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E3EFC47DD9 for ; Thu, 22 Feb 2024 23:17:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6916A6B00A6; Thu, 22 Feb 2024 18:16:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 61E1D6B00AC; Thu, 22 Feb 2024 18:16:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 279156B00A8; Thu, 22 Feb 2024 18:16:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 01F586B00A7 for ; Thu, 22 Feb 2024 18:16:56 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D174E161037 for ; Thu, 22 Feb 2024 23:16:55 +0000 (UTC) X-FDA: 81821001990.16.FB58E47 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf26.hostedemail.com (Postfix) with ESMTP id 99021140007 for ; Thu, 22 Feb 2024 23:16:53 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="H/wcZInY"; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf26.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643813; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TYpwdT9rGpGU+Krn2HEFIYzazdkjNtusHFYwxcfsZAg=; b=qobTI0iVHBar9x/trjlBoPNawL9WJuEui8nTV1P0YQ3FxCWeXAwPdj1SVgYwqVjy0fMH9G 2CCemuJPOZadCGnir4l0YWGPGqWTYwkEidHkBEHenU8kAWBXZ7uhbRL13e5u3VOT7X8H/S vOnvKqrmnF0D13we3NgvZIjh6ZlCwqk= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="H/wcZInY"; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf26.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643813; a=rsa-sha256; cv=none; b=hREWGCsVC2imXD9Ur9/BCq0+nJP8yasWQNkQg3lEBfQpMNh9IwWs7o5qDyIBnMatXNgy0Q LAg/1DptgeBD8022vEFz4wUQwOcJRfBvRknWlX0lNl8BDS6YwZY4+ydNfMEkm1Gy6kJN+6 Lh5lAXmu++jDf2AUB33EFO41Tv3mIpI= Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLxFWt026010; Thu, 22 Feb 2024 23:16:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=TYpwdT9rGpGU+Krn2HEFIYzazdkjNtusHFYwxcfsZAg =; b=H/wcZInYw9DqA1TKF4h0M7BlAGWNbQ/KfRny3iN9QUXCd6MjSpbRIVxfHfV lpWPKSJJGOieAjX02AuK0oeVlSf+DVbKSnX0/8hdRsnj0WjcRFHQrC7hrV6mp3a0 g+SSrCh2RhbLPB7o+ArRjNDoPVOTP7BkLo6ZnF1Nmy7hsRv6kHbZW3UZVHk32BCy cDyBcSE0AW4zE/H+XUDLf8Y0RPzRQUjb5yh3exulGyN+mZ8MM574OiXn4S1CFvzA fKUsURJwYneSWnFIsN8Tj3lYAZey8o4mTjPFu3nu+3bp99l+PH808lPkEZ250J7n IEMyWYcLRTaUBLVgL4+67118wHg== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we24ajumj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:46 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGj5M028219 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:45 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:44 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:55 -0800 Subject: [PATCH v17 32/35] virt: gunyah: Add irqfd interface MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-32-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 4M5Sctox9093hyrqv1fhYVdp-QAefRVI X-Proofpoint-ORIG-GUID: 4M5Sctox9093hyrqv1fhYVdp-QAefRVI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 adultscore=0 mlxlogscore=999 phishscore=0 spamscore=0 mlxscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: 99021140007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: wxg3idcw7543mgo6s7whx9dfg4bstf95 X-HE-Tag: 1708643813-323691 X-HE-Meta: U2FsdGVkX18Ot/oG6ViMHX7qKqUulRZue9yihuxbuXxs/krysd+to/APuFNW6OGnro4/P2h6IYGTeTNc53xZGcwDApzz8NBa+f52nUPBvIdNdnWchhudKthZ5jyPv2a4zTzsqWMq2SGsIX116u+T4azexFz11yH3r9WonjAXcY4mATyRB9dd1P6ffI8F5eoYhWEodWGrHGyapHirUNvihN8CHbRAT9NYEAmot1uCSCLZaNIjtmJo2Iz0Rz40PXv3WGSFwkuCtmyuaJCzdbPwz7Ee7GhjOdqMhKJa0+4ZZRobEhDL5yX9NU0UTT7rw/cXz9IDAsObf4aa2ecRO6X2X0/xkDL2t3jXv1sGx0X47KqlSsMxtg7Ke8NAdKJ77RVKG2YcMcU2oAwonky5muHo9FXVjK06q7CSW4jzasJC81ye1OUBLt30VoKxUpfFHSTiyscHk74QYZi+otgnqjZNPIVpGIAEVGLj4+ybewSGCwuJYhR2yLmE8SkK6wAqRma/pYLnhRG9Sddh/AcP/acU0xE7c/4RE4S3l4m26eMzuevEhatj0mn0fJCM//RqixibNSeBERFF7/jvgVddyZp0pVZrGiX4RB8TfIPmtWCLY2qdfFrWaLul1oPbUlZmPgA3TDukqiH/f3vqyOiiIo+XUiRdDGepkSTEtSKIaLoXI9TzKht7bgRa7u0jCkru4KM3Zss/HXVoyKKmItDWEdl2tYSR1uQKPS4M3BIN9Vkshc//m962el9IzwUwsbFyAOV+cVCwjoN+3EnPz9KV2ud8Zrz9WfXQ55A/7JaeLclTGdO94YzPMjz0C48o5o6y+UjTAA6Mw60VitNonwf+D8gqUQsdCZCpxJaqXgrISdTOryPqfeKAwW81+MKKmw68hK+BEYRoP/A6+RNW9UFBUIupUtVDTgMPvSC2hNVSbMGZXBH0fTmF9vXzUgPUfSa6uOxhRCOJgN/2zIs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable support for creating irqfds which can raise an interrupt on a Gunyah virtual machine. irqfds are exposed to userspace as a Gunyah VM function with the name "irqfd". If the VM devicetree is not configured to create a doorbell with the corresponding label, userspace will still be able to assert the eventfd but no interrupt will be raised on the guest. Acked-by: Alex Elder Co-developed-by: Prakruthi Deepak Heragu Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman --- drivers/virt/gunyah/Kconfig | 9 ++ drivers/virt/gunyah/Makefile | 1 + drivers/virt/gunyah/gunyah_irqfd.c | 187 +++++++++++++++++++++++++++++++++++++ include/uapi/linux/gunyah.h | 35 +++++++ 4 files changed, 232 insertions(+) diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig index fe2823dc48bac..1685b75fb77a0 100644 --- a/drivers/virt/gunyah/Kconfig +++ b/drivers/virt/gunyah/Kconfig @@ -27,3 +27,12 @@ config GUNYAH_QCOM_PLATFORM extra platform-specific support. Say Y/M here to use Gunyah on Qualcomm platforms. + +config GUNYAH_IRQFD + tristate "Gunyah irqfd interface" + depends on GUNYAH + help + Enable kernel support for creating irqfds which can raise an interrupt + on Gunyah virtual machine. + + Say Y/M here if unsure and you want to support Gunyah VMMs. diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index c4505fce177dd..b41b02792921c 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -5,3 +5,4 @@ gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o vm_mgr_mem.o guest_memfd.o obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o gunyah_vcpu.o obj-$(CONFIG_GUNYAH_PLATFORM_HOOKS) += gunyah_platform_hooks.o obj-$(CONFIG_GUNYAH_QCOM_PLATFORM) += gunyah_qcom.o +obj-$(CONFIG_GUNYAH_IRQFD) += gunyah_irqfd.o diff --git a/drivers/virt/gunyah/gunyah_irqfd.c b/drivers/virt/gunyah/gunyah_irqfd.c new file mode 100644 index 0000000000000..951da6e8d321e --- /dev/null +++ b/drivers/virt/gunyah/gunyah_irqfd.c @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct gunyah_irqfd { + struct gunyah_resource *ghrsc; + struct gunyah_vm_resource_ticket ticket; + struct gunyah_vm_function_instance *f; + + bool level; + + struct eventfd_ctx *ctx; + wait_queue_entry_t wait; + poll_table pt; +}; + +static int irqfd_wakeup(wait_queue_entry_t *wait, unsigned int mode, int sync, + void *key) +{ + struct gunyah_irqfd *irqfd = + container_of(wait, struct gunyah_irqfd, wait); + __poll_t flags = key_to_poll(key); + int ret = 0; + + if (flags & EPOLLIN) { + if (irqfd->ghrsc) { + ret = gunyah_hypercall_bell_send(irqfd->ghrsc->capid, 1, + NULL); + if (ret) + pr_err_ratelimited( + "Failed to inject interrupt %d: %d\n", + irqfd->ticket.label, ret); + } else + pr_err_ratelimited( + "Premature injection of interrupt\n"); + } + + return 0; +} + +static void irqfd_ptable_queue_proc(struct file *file, wait_queue_head_t *wqh, + poll_table *pt) +{ + struct gunyah_irqfd *irq_ctx = + container_of(pt, struct gunyah_irqfd, pt); + + add_wait_queue(wqh, &irq_ctx->wait); +} + +static bool gunyah_irqfd_populate(struct gunyah_vm_resource_ticket *ticket, + struct gunyah_resource *ghrsc) +{ + struct gunyah_irqfd *irqfd = + container_of(ticket, struct gunyah_irqfd, ticket); + int ret; + + if (irqfd->ghrsc) { + pr_warn("irqfd%d already got a Gunyah resource. Check if multiple resources with same label were configured.\n", + irqfd->ticket.label); + return false; + } + + irqfd->ghrsc = ghrsc; + if (irqfd->level) { + /* Configure the bell to trigger when bit 0 is asserted (see + * irq_wakeup) and for bell to automatically clear bit 0 once + * received by the VM (ack_mask). need to make sure bit 0 is cleared right away, + * otherwise the line will never be deasserted. Emulating edge + * trigger interrupt does not need to set either mask + * because irq is listed only once per gunyah_hypercall_bell_send + */ + ret = gunyah_hypercall_bell_set_mask(irqfd->ghrsc->capid, 1, 1); + if (ret) + pr_warn("irq %d couldn't be set as level triggered. Might cause IRQ storm if asserted\n", + irqfd->ticket.label); + } + + return true; +} + +static void gunyah_irqfd_unpopulate(struct gunyah_vm_resource_ticket *ticket, + struct gunyah_resource *ghrsc) +{ +} + +static long gunyah_irqfd_bind(struct gunyah_vm_function_instance *f) +{ + struct gunyah_fn_irqfd_arg *args = f->argp; + struct gunyah_irqfd *irqfd; + __poll_t events; + struct fd fd; + long r; + + if (f->arg_size != sizeof(*args)) + return -EINVAL; + + /* All other flag bits are reserved for future use */ + if (args->flags & ~GUNYAH_IRQFD_FLAGS_LEVEL) + return -EINVAL; + + irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL); + if (!irqfd) + return -ENOMEM; + + irqfd->f = f; + f->data = irqfd; + + fd = fdget(args->fd); + if (!fd.file) { + kfree(irqfd); + return -EBADF; + } + + irqfd->ctx = eventfd_ctx_fileget(fd.file); + if (IS_ERR(irqfd->ctx)) { + r = PTR_ERR(irqfd->ctx); + goto err_fdput; + } + + if (args->flags & GUNYAH_IRQFD_FLAGS_LEVEL) + irqfd->level = true; + + init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup); + init_poll_funcptr(&irqfd->pt, irqfd_ptable_queue_proc); + + irqfd->ticket.resource_type = GUNYAH_RESOURCE_TYPE_BELL_TX; + irqfd->ticket.label = args->label; + irqfd->ticket.owner = THIS_MODULE; + irqfd->ticket.populate = gunyah_irqfd_populate; + irqfd->ticket.unpopulate = gunyah_irqfd_unpopulate; + + r = gunyah_vm_add_resource_ticket(f->ghvm, &irqfd->ticket); + if (r) + goto err_ctx; + + events = vfs_poll(fd.file, &irqfd->pt); + if (events & EPOLLIN) + pr_warn("Premature injection of interrupt\n"); + fdput(fd); + + return 0; +err_ctx: + eventfd_ctx_put(irqfd->ctx); +err_fdput: + fdput(fd); + kfree(irqfd); + return r; +} + +static void gunyah_irqfd_unbind(struct gunyah_vm_function_instance *f) +{ + struct gunyah_irqfd *irqfd = f->data; + u64 cnt; + + eventfd_ctx_remove_wait_queue(irqfd->ctx, &irqfd->wait, &cnt); + gunyah_vm_remove_resource_ticket(irqfd->f->ghvm, &irqfd->ticket); + eventfd_ctx_put(irqfd->ctx); + kfree(irqfd); +} + +static bool gunyah_irqfd_compare(const struct gunyah_vm_function_instance *f, + const void *arg, size_t size) +{ + const struct gunyah_fn_irqfd_arg *instance = f->argp, *other = arg; + + if (sizeof(*other) != size) + return false; + + return instance->label == other->label; +} + +DECLARE_GUNYAH_VM_FUNCTION_INIT(irqfd, GUNYAH_FN_IRQFD, 2, gunyah_irqfd_bind, + gunyah_irqfd_unbind, gunyah_irqfd_compare); +MODULE_DESCRIPTION("Gunyah irqfd VM Function"); +MODULE_LICENSE("GPL"); diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index 574116f544722..cb7b0bb9bef38 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -63,9 +63,12 @@ struct gunyah_vm_dtb_config { * @GUNYAH_FN_VCPU: create a vCPU instance to control a vCPU * &struct gunyah_fn_desc.arg is a pointer to &struct gunyah_fn_vcpu_arg * Return: file descriptor to manipulate the vcpu. + * @GUNYAH_FN_IRQFD: register eventfd to assert a Gunyah doorbell + * &struct gunyah_fn_desc.arg is a pointer to &struct gunyah_fn_irqfd_arg */ enum gunyah_fn_type { GUNYAH_FN_VCPU = 1, + GUNYAH_FN_IRQFD, }; #define GUNYAH_FN_MAX_ARG_SIZE 256 @@ -85,6 +88,38 @@ struct gunyah_fn_vcpu_arg { __u32 id; }; +/** + * enum gunyah_irqfd_flags - flags for use in gunyah_fn_irqfd_arg + * @GUNYAH_IRQFD_FLAGS_LEVEL: make the interrupt operate like a level triggered + * interrupt on guest side. Triggering IRQFD before + * guest handles the interrupt causes interrupt to + * stay asserted. + */ +enum gunyah_irqfd_flags { + GUNYAH_IRQFD_FLAGS_LEVEL = 1UL << 0, +}; + +/** + * struct gunyah_fn_irqfd_arg - Arguments to create an irqfd function. + * + * Create this function with &GUNYAH_VM_ADD_FUNCTION using type &GUNYAH_FN_IRQFD. + * + * Allows setting an eventfd to directly trigger a guest interrupt. + * irqfd.fd specifies the file descriptor to use as the eventfd. + * irqfd.label corresponds to the doorbell label used in the guest VM's devicetree. + * + * @fd: an eventfd which when written to will raise a doorbell + * @label: Label of the doorbell created on the guest VM + * @flags: see &enum gunyah_irqfd_flags + * @padding: padding bytes + */ +struct gunyah_fn_irqfd_arg { + __u32 fd; + __u32 label; + __u32 flags; + __u32 padding; +}; + /** * struct gunyah_fn_desc - Arguments to create a VM function * @type: Type of the function. See &enum gunyah_fn_type. From patchwork Thu Feb 22 23:16:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B646C54E49 for ; Thu, 22 Feb 2024 23:18:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F26B36B00AD; Thu, 22 Feb 2024 18:16:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EAE996B00AE; Thu, 22 Feb 2024 18:16:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB0FC6B00AF; Thu, 22 Feb 2024 18:16:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AD2C46B00AE for ; Thu, 22 Feb 2024 18:16:57 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 83A4F40F65 for ; Thu, 22 Feb 2024 23:16:57 +0000 (UTC) X-FDA: 81821002074.06.FE2AAC9 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf05.hostedemail.com (Postfix) with ESMTP id 985F4100013 for ; Thu, 22 Feb 2024 23:16:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=IDTBGxDV; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf05.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643815; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qh+jPnXSbiXkdzqCKqtelkO/e60PKZzxBC0LGQzikQc=; b=xubPfD5zyAayPtQS1SpE9YlrFfRgA9YsIfJ79xMzHAvApvL66iNtO/M8+POXa0caP22gLH +DIL19rTJt+2UxQ2rymVEwmeot3KxAVGoRBUwrt2vk2eTgZn5fPAvC++YVah5KOmxFEpB7 EbzZNhDXpFVPSYGCQ55vTdHCa5eT3aU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=IDTBGxDV; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf05.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643815; a=rsa-sha256; cv=none; b=WF9IfSdynZTgb2epQKTnoVvjFKbBGFVMWhKI5hUWwD26RaxZETyrlZHvBkaseuBjfW40nc ueESPqXRpNaYcfu2W2KUOa8TfzA4Var9sqFWqPZIRGA6taxuzye3Q4xGSb98mYlEiGnKsW i1y3Klo7/Z4UVJ8YQ2XBM5dij6sUHuI= Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLfuAN024795; Thu, 22 Feb 2024 23:16:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=qh+jPnXSbiXkdzqCKqtelkO/e60PKZzxBC0LGQzikQc =; b=IDTBGxDVMlOnY9TRPjx4tn4PXf17/qS4NpZe+wOYSSQw3iNSpU6nagDoQtU lOfNy+ctynbmIER1vf6k7eVjaJ5TZ527gZzso64lNSuy1MbsTXzYWLJ4AJppev60 1JoxGYk6Z/xgM2ufdsF+tKvtlpk8va6rog29gvVVHWYvABhKJRfAUQkqGKK8LIZe qXKe6Cq/jx2vnY0oWB3g/2DH4RZR4nS4Bhs1WAqFyKSuWrVMJd2Mh5Ano6euMOIL wyQBJ38QGUjEn+gipIe2o1MH/SO/A4MjcJ+nx2KgpIIEnZbZXICRiEPu+ZMhq/eV d5eY2NgnIM/UorcVShQACEI3cVQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we4dq17sy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:47 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGklC028227 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:46 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:45 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:56 -0800 Subject: [PATCH v17 33/35] virt: gunyah: Add IO handlers MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-33-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: _RzcJvsLBoQGikWouASJqOQmU4qKmExK X-Proofpoint-ORIG-GUID: _RzcJvsLBoQGikWouASJqOQmU4qKmExK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 adultscore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 985F4100013 X-Stat-Signature: dasztesot6qsujxbxi7a1zmhszjsb5o7 X-Rspam-User: X-HE-Tag: 1708643815-925483 X-HE-Meta: U2FsdGVkX1/LyeG2U90MW+k0iBAY/VL9leNax8wggIGnYaQsVySQC4vOh1KK9lR0PmdIC/gMPapufWth0TGPBvhwl73eN6RAYvwZxJYcBTxtwA5gQe2uOwEFtIp9UYk9leEdTjdwc7YWRIe17j2YCh46VPb3jSxWDo0fV7WuTV3BmHv3qQeROBIcGrYhjLqTvCLwQGmWvI6Hr+2o7MoUByF9s7v6A0ScVWlpMY32LGUQudOKrZ3hKEdA4w15nRaiI51Uc7DC02kQGSWVRmTe3DHz2h2kF40Ah+Dr3lRDWmCpzusqyZf+G7JZ4rzrAsgrIWe8WYAigwQYI7gzs7e4nBdIYgdlniLa87pdAoaZGdR6B074JsP1WGz7BSfr2OukVCuZub48bDGOul6zyw/38Q1zYc1Qf+9KHo5/1ggKAm5Qm21wZKxJlER2wfkcktlp99d4uZ+aCaNye1cCYO0pgfez3th4Wy1tNSwT4a93GxtRcei2qtJOm87W92RsRWOYmJ2l0ME4mRC9WUbnehUB+Y754p5gyqHtBtyGG6D69v7MBcG+YltbZtnkquTZattI4XjsQBDbJje6rIOCz1PALXFl1ly6HE31YRex8Kt2z4AseJvRF2xIjr4eI6jWsHpLb0gTy9voRVS7hhVvJzVq4kPMn0/R19xnDmGNoX0XlkprM6XS+fD/vfImFZLKGJvjmBlRW0mZsxnmhfU26j9sNTFXjeettL091thkyFcwxyqhkrDyKx6njQYJ/itAEEnUU/EPDlsROblzJx/qYEaZebNjfORvF9yYiEHmb8teE3EHyDdnus+Uzo6AORpoDEhOhh8dNzIX7AkY5Hgsyywc6NZQ8M0+rl9suGLupLIJbRvf60l3VbT3zzWusbCZTDk0H6xIsFoHMFKaQaJeV7jhGO7eGZQ5hTU8IcPgwUnXp6QS6kNAxlbkuo5pBvbDMI1CjVPvSb0BejY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add framework for VM functions to handle stage-2 write faults from Gunyah guest virtual machines. IO handlers have a range of addresses which they apply to. Optionally, they may apply to only when the value written matches the IO handler's value. Reviewed-by: Alex Elder Co-developed-by: Prakruthi Deepak Heragu Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman --- drivers/virt/gunyah/gunyah_vcpu.c | 4 ++ drivers/virt/gunyah/vm_mgr.c | 115 ++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/vm_mgr.h | 8 +++ include/linux/gunyah.h | 29 ++++++++++ 4 files changed, 156 insertions(+) diff --git a/drivers/virt/gunyah/gunyah_vcpu.c b/drivers/virt/gunyah/gunyah_vcpu.c index f8306620b1dd6..ef78503fe586d 100644 --- a/drivers/virt/gunyah/gunyah_vcpu.c +++ b/drivers/virt/gunyah/gunyah_vcpu.c @@ -133,6 +133,10 @@ gunyah_handle_mmio(struct gunyah_vcpu *vcpu, unsigned long resume_data[3], vcpu->state = GUNYAH_VCPU_RUN_STATE_MMIO_READ; vcpu->mmio_read_len = len; } else { /* GUNYAH_VCPU_ADDRSPACE_VMMIO_WRITE */ + if (!gunyah_vm_mmio_write(vcpu->ghvm, addr, len, data)) { + resume_data[0] = GUNYAH_ADDRSPACE_VMMIO_ACTION_EMULATE; + return true; + } vcpu->vcpu_run->mmio.is_write = 1; memcpy(vcpu->vcpu_run->mmio.data, &data, len); vcpu->state = GUNYAH_VCPU_RUN_STATE_MMIO_WRITE; diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index a61a3f3ae92f1..2434be5dffe08 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -302,6 +302,118 @@ static void gunyah_vm_clean_resources(struct gunyah_vm *ghvm) mutex_unlock(&ghvm->resources_lock); } +static int _gunyah_vm_io_handler_compare(const struct rb_node *node, + const struct rb_node *parent) +{ + struct gunyah_vm_io_handler *n = + container_of(node, struct gunyah_vm_io_handler, node); + struct gunyah_vm_io_handler *p = + container_of(parent, struct gunyah_vm_io_handler, node); + + if (n->addr < p->addr) + return -1; + if (n->addr > p->addr) + return 1; + if ((n->len && !p->len) || (!n->len && p->len)) + return 0; + if (n->len < p->len) + return -1; + if (n->len > p->len) + return 1; + /* one of the io handlers doesn't have datamatch and the other does. + * For purposes of comparison, that makes them identical since the + * one that doesn't have datamatch will cover the same handler that + * does. + */ + if (n->datamatch != p->datamatch) + return 0; + if (n->data < p->data) + return -1; + if (n->data > p->data) + return 1; + return 0; +} + +static int gunyah_vm_io_handler_compare(struct rb_node *node, + const struct rb_node *parent) +{ + return _gunyah_vm_io_handler_compare(node, parent); +} + +static int gunyah_vm_io_handler_find(const void *key, + const struct rb_node *node) +{ + const struct gunyah_vm_io_handler *k = key; + + return _gunyah_vm_io_handler_compare(&k->node, node); +} + +static struct gunyah_vm_io_handler * +gunyah_vm_mgr_find_io_hdlr(struct gunyah_vm *ghvm, u64 addr, u64 len, u64 data) +{ + struct gunyah_vm_io_handler key = { + .addr = addr, + .len = len, + .datamatch = true, + .data = data, + }; + struct rb_node *node; + + node = rb_find(&key, &ghvm->mmio_handler_root, + gunyah_vm_io_handler_find); + if (!node) + return NULL; + + return container_of(node, struct gunyah_vm_io_handler, node); +} + +int gunyah_vm_mmio_write(struct gunyah_vm *ghvm, u64 addr, u32 len, u64 data) +{ + struct gunyah_vm_io_handler *io_hdlr = NULL; + int ret; + + down_read(&ghvm->mmio_handler_lock); + io_hdlr = gunyah_vm_mgr_find_io_hdlr(ghvm, addr, len, data); + if (!io_hdlr || !io_hdlr->ops || !io_hdlr->ops->write) { + ret = -ENOENT; + goto out; + } + + ret = io_hdlr->ops->write(io_hdlr, addr, len, data); + +out: + up_read(&ghvm->mmio_handler_lock); + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_vm_mmio_write); + +int gunyah_vm_add_io_handler(struct gunyah_vm *ghvm, + struct gunyah_vm_io_handler *io_hdlr) +{ + struct rb_node *found; + + if (io_hdlr->datamatch && + (!io_hdlr->len || io_hdlr->len > sizeof(io_hdlr->data))) + return -EINVAL; + + down_write(&ghvm->mmio_handler_lock); + found = rb_find_add(&io_hdlr->node, &ghvm->mmio_handler_root, + gunyah_vm_io_handler_compare); + up_write(&ghvm->mmio_handler_lock); + + return found ? -EEXIST : 0; +} +EXPORT_SYMBOL_GPL(gunyah_vm_add_io_handler); + +void gunyah_vm_remove_io_handler(struct gunyah_vm *ghvm, + struct gunyah_vm_io_handler *io_hdlr) +{ + down_write(&ghvm->mmio_handler_lock); + rb_erase(&io_hdlr->node, &ghvm->mmio_handler_root); + up_write(&ghvm->mmio_handler_lock); +} +EXPORT_SYMBOL_GPL(gunyah_vm_remove_io_handler); + static int gunyah_vm_rm_notification_status(struct gunyah_vm *ghvm, void *data) { struct gunyah_rm_vm_status_payload *payload = data; @@ -404,6 +516,9 @@ static __must_check struct gunyah_vm *gunyah_vm_alloc(struct gunyah_rm *rm) INIT_LIST_HEAD(&ghvm->resource_tickets); xa_init(&ghvm->boot_context); + init_rwsem(&ghvm->mmio_handler_lock); + ghvm->mmio_handler_root = RB_ROOT; + mt_init(&ghvm->mm); mt_init(&ghvm->bindings); init_rwsem(&ghvm->bindings_lock); diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index 8cee93e551700..daddb1d0cb70b 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,9 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, * @guest_shared_extent_ticket: Resource ticket to the capability for * the memory extent that represents * memory shared with the guest. + * @mmio_handler_root: RB tree of MMIO handlers. + * Entries are &struct gunyah_vm_io_handler + * @mmio_handler_lock: Serialization of traversing @mmio_handler_root * @rm: Pointer to the resource manager struct to make RM calls * @parent: For logging * @nb: Notifier block for RM notifications @@ -93,6 +97,8 @@ struct gunyah_vm { struct gunyah_vm_resource_ticket addrspace_ticket, host_private_extent_ticket, host_shared_extent_ticket, guest_private_extent_ticket, guest_shared_extent_ticket; + struct rb_root mmio_handler_root; + struct rw_semaphore mmio_handler_lock; struct gunyah_rm *rm; @@ -119,6 +125,8 @@ struct gunyah_vm { struct xarray boot_context; }; +int gunyah_vm_mmio_write(struct gunyah_vm *ghvm, u64 addr, u32 len, u64 data); + /** * folio_mmapped() - Returns true if the folio is mapped into any vma * @folio: Folio to test diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index a9d58150de696..dbd5b0251b491 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -155,6 +155,35 @@ int gunyah_vm_add_resource_ticket(struct gunyah_vm *ghvm, void gunyah_vm_remove_resource_ticket(struct gunyah_vm *ghvm, struct gunyah_vm_resource_ticket *ticket); +/* + * gunyah_vm_io_handler contains the info about an io device and its associated + * addr and the ops associated with the io device. + */ +struct gunyah_vm_io_handler { + struct rb_node node; + u64 addr; + + bool datamatch; + u8 len; + u64 data; + struct gunyah_vm_io_handler_ops *ops; +}; + +/* + * gunyah_vm_io_handler_ops contains function pointers associated with an iodevice. + */ +struct gunyah_vm_io_handler_ops { + int (*read)(struct gunyah_vm_io_handler *io_dev, u64 addr, u32 len, + u64 data); + int (*write)(struct gunyah_vm_io_handler *io_dev, u64 addr, u32 len, + u64 data); +}; + +int gunyah_vm_add_io_handler(struct gunyah_vm *ghvm, + struct gunyah_vm_io_handler *io_dev); +void gunyah_vm_remove_io_handler(struct gunyah_vm *ghvm, + struct gunyah_vm_io_handler *io_dev); + #define GUNYAH_RM_ACL_X BIT(0) #define GUNYAH_RM_ACL_W BIT(1) #define GUNYAH_RM_ACL_R BIT(2) From patchwork Thu Feb 22 23:16:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 960C7C54E49 for ; Thu, 22 Feb 2024 23:18:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F35C6B00A8; Thu, 22 Feb 2024 18:16:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 07BC46B00AA; Thu, 22 Feb 2024 18:16:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E107E6B00AC; Thu, 22 Feb 2024 18:16:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C89846B00A8 for ; Thu, 22 Feb 2024 18:16:56 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A758B40F62 for ; Thu, 22 Feb 2024 23:16:56 +0000 (UTC) X-FDA: 81821002032.11.110CCB2 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf26.hostedemail.com (Postfix) with ESMTP id 83FB1140003 for ; Thu, 22 Feb 2024 23:16:54 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=FjtDETKc; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf26.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643814; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JCvR/F4e78SINAjN3meQYZzTInDObRjxvrSnXKpjai8=; b=ksmuwk9fkaOZEetKHQVWZFv/GvNgSuXYtsy8REpRdnWK0h7xkrb6vERXhdRC975yXXagIP 1vSMZdCcfFMu95o+XxVt/jT+31Q1LqyuoH2IQ2xVwZ8gx7dpflUIDbnAV8J0uNxg8paW10 W2CoXI5hEexf+ZhBD4OO0nHB1CrCJbQ= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=FjtDETKc; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf26.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643814; a=rsa-sha256; cv=none; b=gXQoe2aE+egCvXdiqKWT8q7fyjCID/A3wU7bysGPnmgNVgoJa2LYcot4O3CnMHXwqsUvrr iaaPgZJ6qyEjo/w7x9zSq7ci8BKz4vm6r1REsRa9eIe0TYNHyD4DfQquT30DjArhte0sI0 elzJDK49XSTjltnZGvU/5b8rFWFRu0c= Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLcfsx010074; Thu, 22 Feb 2024 23:16:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=JCvR/F4e78SINAjN3meQYZzTInDObRjxvrSnXKpjai8 =; b=FjtDETKc/0YZ7h6GsKOoYFC95XN1GsWS2Ki6KfHY2R09+DyalIWE4XK7eaG 5aC38FRjcTiPbwP5lRGFYahhT06fipPKURtl9nqKSKb4VaCOijdCriHT0qVs5DUV 2HLU6KSWWB4Y998qRUphry2pqZOIFsB/fkEQWBnbD4LATnYjqzCEAbOesOD27S12 GxP2S/08Jc0e06MV/j7Xrzkbr2e0Ekrpf0n1SHupWlsxfshnwO1okTdANJ7jPPi5 rmkQ9HFUniWnK18W50p9Ax4jhJh5hsmazkDvDbziXOefss+7giMVTPZxh82UDa0D BnuL1XOK4Ez8i2eLVSXgH7fi9GA== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we2kf9puv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:47 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGksh025676 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:46 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:46 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:57 -0800 Subject: [PATCH v17 34/35] virt: gunyah: Add ioeventfd MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-34-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: bWGKXIzCtCgdXv3iBnUxn_P4tDEUuHGp X-Proofpoint-GUID: bWGKXIzCtCgdXv3iBnUxn_P4tDEUuHGp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=0 phishscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: 83FB1140003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 64fr9eqnmfgare85jrfmwx8gfsqco7bj X-HE-Tag: 1708643814-2167 X-HE-Meta: U2FsdGVkX1+Rdmhjdwapeo/hheXmuK6nAkLNBt1QM0uLp78MmhlctDvXN/HdmIt8E/w1+Ur1cDHjGgGIyzxa6CrAtQfXUGNtngPhRIJf4SUK5ivoTRcfBkEpqEuzwHwzJNfKhZgNPuul4BxKmrR7uE/qVn3Cr7+1nOTelc6b8tSpuRmrGSgEv28Hgf6++ct+P9WKOiZoc5o8Y8XO2v4526BBLxWmo7vBU2HNbsCDAgORPoeADEQCUDOSgjh+KJp7tLnL8y0x1DPuZn2g9h9+QLEnJmrd1qoX5UqKkLcd/+2FEn95DKhOsUIz3QDr6DkiQetOwfluIlyoq06pD9DtxMJVbdsNGNht6pLrkpQWMOlZrIaVWD20TrpVCVpi9UaCRm8v+BRVptvpoHVQwY3E8o6Xm5eGbu5uCfNCZaFz8sf+h4HNlNrCBFAZ0ph/GehVOkXqiLBu851T41u2p0fUeWNQS5559MQwxsDgjT/SYyUAcwTv+cxdbifo8nOeGhT8C7Jc3zKfM+kB30GYDRe5Xn/8QD4QtFmaVyl5uIqIVZfsPo99cvLAn/dyFTMxbdb7V2L9r3SpVC2GMYNr6eFOo4hAS9Z4xN9j4coZ1EPuR8ggfMTQ5nv7DPaE9T6U1xPTGRwe9dFsoS0klUe6xF/9BxsQrkez2Yc6US0FIUJ2iC5Bu2OnZYSmmk6TiJxvv4Z1He7hzz67qbVYNnjGHgwoq4xh2/Cl48zWdBP9wCUVNiCgIH6JVjqUTkjM/n2iM/OI0Q4591HwoRd1LKT1s2LLJhSuSq4/AD/Fh+3FZirZjTK1saymYtMCPn97sORLdpMIt6dbNot32oVziu3tqa2uDG/Ci43KfJc2hg95z8LV+iwxCB/chGKhocCwHH/RjzpC0+IKRupA1rhXKN9IKZ+ayeGE1I8qjHmPRMmYssJkc1kE4GDSo+Bph0+jwOMonyWhPk+3ric0flxb2QpUKGV +ElzU//3 QuwZmGvnGsKRr/i+0GWu/sEqUCQb96JgUqLGZw/Fal54u/+ml+JOT9ED7JN5QcbkaDiG2LRiFLlyfpqAvKCvTG7nHft+MSQiBAOtp6jOIBAeB2ksytfHlAqPuex4Hwm9lpwQjwsxf+jIlDPo4NNEpQmHZqJr83idht2nxLb2oI61irKgeLm+kKoGUonkAqPEbEeaMUd7I3sxbAtRJztjUHvvTE0cTcE0S9YEqXjT3DQprVip7dTPSHeXNtocT6+FMUXds7ozlfVGct6tBcpYBlTuSKAcGWGf/cby2gifO3/3gD/u52WDFoR3pDtE9veiJaKX8ckbQkLCdkT7B3ZXl7F+jpKVwitavLIoPDHA3AVq29jodPXSKMAd+1gcAbLafZQ4qkEqptqmryO5zI9pLN1NnHP1ZFSAScvYfEfGfb1dtrB9eEcmkI0ctaSQEpyHSFoWriRsrmp/n8uiiUhjrm/5Dkg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Allow userspace to attach an ioeventfd to an mmio address within the guest. Userspace provides a description of the type of write to "subscribe" to and eventfd to trigger when that type of write is performed by the guest. This mechanism allows userspace to respond asynchronously to a guest manipulating a virtualized device and is similar to KVM's ioeventfd. Reviewed-by: Alex Elder Co-developed-by: Prakruthi Deepak Heragu Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman --- drivers/virt/gunyah/Kconfig | 9 +++ drivers/virt/gunyah/Makefile | 1 + drivers/virt/gunyah/gunyah_ioeventfd.c | 139 +++++++++++++++++++++++++++++++++ include/uapi/linux/gunyah.h | 37 +++++++++ 4 files changed, 186 insertions(+) diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig index 1685b75fb77a0..855d41a88b160 100644 --- a/drivers/virt/gunyah/Kconfig +++ b/drivers/virt/gunyah/Kconfig @@ -36,3 +36,12 @@ config GUNYAH_IRQFD on Gunyah virtual machine. Say Y/M here if unsure and you want to support Gunyah VMMs. + +config GUNYAH_IOEVENTFD + tristate "Gunyah ioeventfd interface" + depends on GUNYAH + help + Enable kernel support for creating ioeventfds which can alert userspace + when a Gunyah virtual machine accesses a memory address. + + Say Y/M here if unsure and you want to support Gunyah VMMs. diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index b41b02792921c..2aec5989402b0 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_GUNYAH) += gunyah.o gunyah_rsc_mgr.o gunyah_vcpu.o obj-$(CONFIG_GUNYAH_PLATFORM_HOOKS) += gunyah_platform_hooks.o obj-$(CONFIG_GUNYAH_QCOM_PLATFORM) += gunyah_qcom.o obj-$(CONFIG_GUNYAH_IRQFD) += gunyah_irqfd.o +obj-$(CONFIG_GUNYAH_IOEVENTFD) += gunyah_ioeventfd.o diff --git a/drivers/virt/gunyah/gunyah_ioeventfd.c b/drivers/virt/gunyah/gunyah_ioeventfd.c new file mode 100644 index 0000000000000..894d303968c4c --- /dev/null +++ b/drivers/virt/gunyah/gunyah_ioeventfd.c @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +struct gunyah_ioeventfd { + struct gunyah_vm_function_instance *f; + struct gunyah_vm_io_handler io_handler; + + struct eventfd_ctx *ctx; +}; + +static int gunyah_write_ioeventfd(struct gunyah_vm_io_handler *io_dev, u64 addr, + u32 len, u64 data) +{ + struct gunyah_ioeventfd *iofd = + container_of(io_dev, struct gunyah_ioeventfd, io_handler); + + eventfd_signal(iofd->ctx); + return 0; +} + +static struct gunyah_vm_io_handler_ops io_ops = { + .write = gunyah_write_ioeventfd, +}; + +static long gunyah_ioeventfd_bind(struct gunyah_vm_function_instance *f) +{ + const struct gunyah_fn_ioeventfd_arg *args = f->argp; + struct gunyah_ioeventfd *iofd; + struct eventfd_ctx *ctx; + int ret; + + if (f->arg_size != sizeof(*args)) + return -EINVAL; + + /* All other flag bits are reserved for future use */ + if (args->flags & ~GUNYAH_IOEVENTFD_FLAGS_DATAMATCH) + return -EINVAL; + + /* must be natural-word sized, or 0 to ignore length */ + switch (args->len) { + case 0: + case 1: + case 2: + case 4: + case 8: + break; + default: + return -EINVAL; + } + + /* check for range overflow */ + if (overflows_type(args->addr + args->len, u64)) + return -EINVAL; + + /* ioeventfd with no length can't be combined with DATAMATCH */ + if (!args->len && (args->flags & GUNYAH_IOEVENTFD_FLAGS_DATAMATCH)) + return -EINVAL; + + ctx = eventfd_ctx_fdget(args->fd); + if (IS_ERR(ctx)) + return PTR_ERR(ctx); + + iofd = kzalloc(sizeof(*iofd), GFP_KERNEL); + if (!iofd) { + ret = -ENOMEM; + goto err_eventfd; + } + + f->data = iofd; + iofd->f = f; + + iofd->ctx = ctx; + + if (args->flags & GUNYAH_IOEVENTFD_FLAGS_DATAMATCH) { + iofd->io_handler.datamatch = true; + iofd->io_handler.len = args->len; + iofd->io_handler.data = args->datamatch; + } + iofd->io_handler.addr = args->addr; + iofd->io_handler.ops = &io_ops; + + ret = gunyah_vm_add_io_handler(f->ghvm, &iofd->io_handler); + if (ret) + goto err_io_dev_add; + + return 0; + +err_io_dev_add: + kfree(iofd); +err_eventfd: + eventfd_ctx_put(ctx); + return ret; +} + +static void gunyah_ioevent_unbind(struct gunyah_vm_function_instance *f) +{ + struct gunyah_ioeventfd *iofd = f->data; + + gunyah_vm_remove_io_handler(iofd->f->ghvm, &iofd->io_handler); + eventfd_ctx_put(iofd->ctx); + kfree(iofd); +} + +static bool gunyah_ioevent_compare(const struct gunyah_vm_function_instance *f, + const void *arg, size_t size) +{ + const struct gunyah_fn_ioeventfd_arg *instance = f->argp, *other = arg; + + if (sizeof(*other) != size) + return false; + + if (instance->addr != other->addr || instance->len != other->len || + instance->flags != other->flags) + return false; + + if ((instance->flags & GUNYAH_IOEVENTFD_FLAGS_DATAMATCH) && + instance->datamatch != other->datamatch) + return false; + + return true; +} + +DECLARE_GUNYAH_VM_FUNCTION_INIT(ioeventfd, GUNYAH_FN_IOEVENTFD, 3, + gunyah_ioeventfd_bind, gunyah_ioevent_unbind, + gunyah_ioevent_compare); +MODULE_DESCRIPTION("Gunyah ioeventfd VM Function"); +MODULE_LICENSE("GPL"); diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index cb7b0bb9bef38..fd461e2fe8b58 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -65,10 +65,13 @@ struct gunyah_vm_dtb_config { * Return: file descriptor to manipulate the vcpu. * @GUNYAH_FN_IRQFD: register eventfd to assert a Gunyah doorbell * &struct gunyah_fn_desc.arg is a pointer to &struct gunyah_fn_irqfd_arg + * @GUNYAH_FN_IOEVENTFD: register ioeventfd to trigger when VM faults on parameter + * &struct gunyah_fn_desc.arg is a pointer to &struct gunyah_fn_ioeventfd_arg */ enum gunyah_fn_type { GUNYAH_FN_VCPU = 1, GUNYAH_FN_IRQFD, + GUNYAH_FN_IOEVENTFD, }; #define GUNYAH_FN_MAX_ARG_SIZE 256 @@ -120,6 +123,40 @@ struct gunyah_fn_irqfd_arg { __u32 padding; }; +/** + * enum gunyah_ioeventfd_flags - flags for use in gunyah_fn_ioeventfd_arg + * @GUNYAH_IOEVENTFD_FLAGS_DATAMATCH: the event will be signaled only if the + * written value to the registered address is + * equal to &struct gunyah_fn_ioeventfd_arg.datamatch + */ +enum gunyah_ioeventfd_flags { + GUNYAH_IOEVENTFD_FLAGS_DATAMATCH = 1UL << 0, +}; + +/** + * struct gunyah_fn_ioeventfd_arg - Arguments to create an ioeventfd function + * @datamatch: data used when GUNYAH_IOEVENTFD_DATAMATCH is set + * @addr: Address in guest memory + * @len: Length of access + * @fd: When ioeventfd is matched, this eventfd is written + * @flags: See &enum gunyah_ioeventfd_flags + * @padding: padding bytes + * + * Create this function with &GUNYAH_VM_ADD_FUNCTION using type &GUNYAH_FN_IOEVENTFD. + * + * Attaches an ioeventfd to a legal mmio address within the guest. A guest write + * in the registered address will signal the provided event instead of triggering + * an exit on the GUNYAH_VCPU_RUN ioctl. + */ +struct gunyah_fn_ioeventfd_arg { + __u64 datamatch; + __u64 addr; /* legal mmio address */ + __u32 len; /* 1, 2, 4, or 8 bytes; or 0 to ignore length */ + __s32 fd; + __u32 flags; + __u32 padding; +}; + /** * struct gunyah_fn_desc - Arguments to create a VM function * @type: Type of the function. See &enum gunyah_fn_type. From patchwork Thu Feb 22 23:16:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE521C47DD9 for ; Thu, 22 Feb 2024 23:18:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BB446B00AA; Thu, 22 Feb 2024 18:16:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 845E16B00AD; Thu, 22 Feb 2024 18:16:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64A716B00AE; Thu, 22 Feb 2024 18:16:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4EFE06B00AA for ; Thu, 22 Feb 2024 18:16:57 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2986BA1771 for ; Thu, 22 Feb 2024 23:16:57 +0000 (UTC) X-FDA: 81821002074.08.EC8D7B7 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf07.hostedemail.com (Postfix) with ESMTP id E423C40006 for ; Thu, 22 Feb 2024 23:16:54 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=A74ZU4zg; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf07.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643815; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jOwfR/FjmwpUtqpMZm+Fy+OtEj0xIxNWKqW40RmlzwU=; b=cUnNCiAaZONZpKmUdFN7DM/ECIzG+SO884bbltUuAyL4C06IFezytkWeH7DV9n1aZTRbYU rEq6E3OCDbR11dI8XYDQsaalh6z3tMrkXmmYsimAsQfuhubo3iyPt8ZehoHnwGQ78cT0lO 3b/5d3abW+sKXCJDa+wbuaQalay4FZk= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=A74ZU4zg; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf07.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643815; a=rsa-sha256; cv=none; b=XcZ0/y8w3Vq5591Zhq3yD6bcfgcG2lBpEoKkgo44ATd51YniSj36HehbsV7wS1G7/mDVN0 +ByPo5Zva+GekETV8vHOohbZOh8gbCr4/YsEqJ6Sg7vyoJ6XtUcv1iWFrHKtDeeauTtg00 X0wCVAWf9032rttbP/r6sNqjK42LkAo= Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLjx5E007129; Thu, 22 Feb 2024 23:16:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=jOwfR/FjmwpUtqpMZm+Fy+OtEj0xIxNWKqW40RmlzwU =; b=A74ZU4zg/NKqshmuIf5hsrRyYxzH5KLeS3UdiIaLxPQgYad7CHTw31uP0ca j80GMKGYrLEFmWayAhl0Hw8pn+p3K6uUKb9uZmPZnfS16rCpLB6m71gOTcnpvYZl 8KptQ4WaSkZvl9QNLr1Nlv3i8fMBe889aQGqZ1pGCuiZsT6DLeU3ARk6DLN2moiU GpwNJOWP+70GRexPmQea0ymjUk64ThlyN+0d/ko5ZLplfzklN4vcdZ141CcUR/8j dkzCwLpclNDT78tgLFLfYhkiU5C7vJ+w/aA9vyE+TPvtDVpybvxu+MxTzGe6xEi/ yHKZdF8fXDsCwcapr04tosNlTTQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wdvwwbj78-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:48 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGl2k028239 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:47 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:46 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:58 -0800 Subject: [PATCH v17 35/35] MAINTAINERS: Add Gunyah hypervisor drivers section MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-35-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: b-bFkiTBtvVnXQasl01_9c-9b3K8FlZV X-Proofpoint-GUID: b-bFkiTBtvVnXQasl01_9c-9b3K8FlZV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 spamscore=0 impostorscore=0 mlxlogscore=867 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Queue-Id: E423C40006 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 7xmapzydh1t6dp1yid3giq7hj6ecr5mn X-HE-Tag: 1708643814-997283 X-HE-Meta: U2FsdGVkX1/gY8x4ZFl9Qk0ot+JpFiOGX/0MS/w93RtnUJf0ijizg3OTmvZiVDjoK6fbywaECYWRf2bpdijJgYFfeD/YH7AxYAZ4phHJAGeTn+Wge0EEtq+XO/vnqTm35N34zyNIdgnsxmfChkmUmvzw3LrdHRvcnw6ySpCs9GDMdYBfXvbv8xYsMSXQgxmm1dCe04wlT3aNgq4n0/q/NRVc5Nb41ZwaNEMrwnjyNDMPxkwbYI6oB9jE2f/QhVPr577+LgSxfHJvAMeTkChB2+OirZsSMg51YeMzu0UjmuQ3A6DYKlZW2ch28wXg+iDSOKg7oelX7Db3TeH1FVLPODixps8pVvM9K2rxWgQWVtmS6m8bgB/4Yot5x+cACBPFnRoT5TdfJ8aOarum5ZcdHKqYsrrOs/jnsn5USss8xtJ/C0FfVsFF47ZAf+5IXvCHB1xARbnWk0pzYDW6WfWRo0djEtyxXpIAcZi4Pr4pV7Q1IbVm6adBaHH+xYJOPU+6Lcwwn8DVsnelAGx8T0Fh1kzn6qqpTgbnynQ87t49hzz2D371dE6fAE2CaRub/DH8sA8UVUnQ0u333ZsvRq18d4KN6SatTTsdWCo0xv1nc2UWArKvgFtC1MZGNpjDhP7fRJAQS1jZps/34SbHwvO8JWx3wCjYjyEl5TCREeLdYvl+nFPVdnBLuny7yBhd3qT/rIZo4EePUZhPzA9FFD/202jbrolsftUHXYDw9odCA11G+vryZMUhyjWfWY23BonZoCYrLdVlg+xrBk5GYsau0N0kEFJ+WvCeAglhVRz+qwG340n2Qaq8h/9LwHQkRnbcHM9y1IEBu+4lEa026MeQTrKm6LWrNCv/qu9Gnr87cunlYRE+yiyC4sQhB3jJ6PzMQExqwGvyOAojB2qbgyY+DBzT2CsR4ExFXOYMbrrbuqfcMI9pCh5hV6PgypxmYvcx/baCQA81lqj2aWimrYN epU4lkg7 uLMNZGBdRGIEItK69nWHgB3cwXFRcjMbZmmVxXsFd0sG+HwS881pe4mbixYB7uYx8i3UUZE3RmKTTJ8/C2O9iOhTUhifplwbSQJEM5BdemMgOvGa0AyiPRPPjYRkhyCKaspg72Xp/OnBC/5bpbfj7GszdiUOFJiPT4yPDis/x/CAkoTwXD3uUnnhQrUXib7mUeyckkCXkcVrCVWFBjhjgB3SQn2H54xyf6DPzdHNYjUeXG0z00rC6t2COF1vmPNEvDWG92AmtR4jferBsTdGPoR26OK9hlyIFIBlq50Q0QD2D2zLKdIcdi+v2EXlIUja7fm54EbkpMt+bQJPbm3lcoachLQHoSBlEZQjXb7106gfemPKjeXT01cs4jyleurd9lviF1aF5Hcmno2Rkv9m+lLm1y3l0DilFNh5nwIc3R7SE3eh0j/ODZKjekt51o+drhIHkVCGaSX5+TmZUTLIyIE+FssjkTZc657oflF10EZXuToXp+93zog+euuJxSGJAUxwuSLfBKuFTW8uCUlJJCui7PofAmYoCnv4SukvtRyfrhiI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add myself and Prakruthi as maintainers of Gunyah hypervisor drivers. Reviewed-by: Alex Elder Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman --- MAINTAINERS | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index bf77be03fb2b..07d8ea2393a9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9322,6 +9322,18 @@ L: linux-efi@vger.kernel.org S: Maintained F: block/partitions/efi.* +GUNYAH HYPERVISOR DRIVER +M: Elliot Berman +M: Prakruthi Deepak Heragu +L: linux-arm-msm@vger.kernel.org +S: Supported +F: Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml +F: Documentation/virt/gunyah/ +F: arch/arm64/gunyah/ +F: drivers/virt/gunyah/ +F: include/linux/gunyah*.h +K: gunyah + HABANALABS PCI DRIVER M: Oded Gabbay L: dri-devel@lists.freedesktop.org