From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D1BAC6FA90 for ; Wed, 28 Sep 2022 19:57:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234414AbiI1T53 (ORCPT ); Wed, 28 Sep 2022 15:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234320AbiI1T51 (ORCPT ); Wed, 28 Sep 2022 15:57:27 -0400 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C562952E7F; Wed, 28 Sep 2022 12:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1664395045; x=1695931045; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cmwmpm0KFVc+J9NbMuqse/WrCkY3i8NAXtTrYSw7L4c=; b=y9p8DyNQ6mdzqD1MXNpiyLMBgjoPdvkE0GJ6RhSvhtN6dPj6l4JzGboo MI15pc4SLUaT1mn9Qrfgs8kBZXBapNGYCo/+mokePq1H/BX6HMC2r2DBI H5EGc+P3mDV1gbD8C1EpchGj+tJQ/Vmq9RTnsEQcXbgablFvi15tZqSDt 8=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-01.qualcomm.com with ESMTP; 28 Sep 2022 12:57:25 -0700 X-QCInternal: smtphost Received: from nasanex01b.na.qualcomm.com ([10.46.141.250]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 12:57:25 -0700 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.986.29; Wed, 28 Sep 2022 12:57:24 -0700 From: Elliot Berman To: Bjorn Andersson , Jonathan Corbet CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Will Deacon , "Catalin Marinas" , Arnd Bergmann , "Greg Kroah-Hartman" , , , , Subject: [PATCH v4 01/14] docs: gunyah: Introduce Gunyah Hypervisor Date: Wed, 28 Sep 2022 12:56:20 -0700 Message-ID: <20220928195633.2348848-2-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- Documentation/virt/gunyah/index.rst | 114 ++++++++++++++++++++ Documentation/virt/gunyah/message-queue.rst | 52 +++++++++ Documentation/virt/index.rst | 1 + MAINTAINERS | 7 ++ 4 files changed, 174 insertions(+) create mode 100644 Documentation/virt/gunyah/index.rst create mode 100644 Documentation/virt/gunyah/message-queue.rst diff --git a/Documentation/virt/gunyah/index.rst b/Documentation/virt/gunya= h/index.rst new file mode 100644 index 000000000000..959f451caccd --- /dev/null +++ b/Documentation/virt/gunyah/index.rst @@ -0,0 +1,114 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Gunyah Hypervisor +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. toctree:: + :maxdepth: 1 + + message-queue + +Gunyah is a Type-1 hypervisor which is independent of any OS kernel, and r= uns in +a higher CPU privilege level. It does not depend on any lower-privileged o= perating 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 repo is available at +https://github.com/quic/gunyah-hypervisor. + +Gunyah provides these following features. + +- Scheduling: + + A scheduler for virtual CPUs (vCPUs) on physical CPUs and enables time-s= haring + of the CPUs. Gunyah supports two models of scheduling: + + 1. "Behind the back" scheduling in which Gunyah hypervisor schedules v= CPUS on its own + 2. "Proxy" scheduling in which a delegated VM can donate part of one o= f its vCPU slice + to another VM's vCPU via a hypercall. + +- Memory Management: + + APIs handling memory, abstracted as objects, limiting direct use of phys= ical + addresses. Memory ownership and usage tracking of all memory under its c= ontrol. + Memory partitioning between VMs is a fundamental security feature. + +- Interrupt Virtualization: + + Uses CPU hardware interrupt virtualization capabilities. Interrupts are = handled + in the hypervisor and routed to the assigned VM. + +- Inter-VM Communication: + + There are several different mechanisms provided for communicating betwee= n VMs. + +- Virtual platform: + + Architectural devices such as interrupt controllers and CPU timers are d= irectly provided + by the hypervisor as well as core virtual platform devices and system AP= Is such as ARM PSCI. + +- Device Virtualization: + + Para-virtualization of devices is supported using inter-VM communication. + +Architectures supported +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +AArch64 with a GIC + +Resources and Capabilities +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + +Some services or resources provided by the Gunyah hypervisor are described= to a virtual machine by +capability IDs. For instance, inter-VM communication is performed with doo= rbells and message queues. +Gunyah allows access to manipulate that doorbell via the capability ID. Th= ese devices are described +in Linux as a struct gunyah_resource. + +High level management of these resources is performed by the resource mana= ger VM. RM informs a +guest VM about resources it can access through either the device tree or v= ia guest-initiated RPC. + +For each virtual machine, Gunyah maintains a table of resources which can = be accessed by that VM. +An entry in this table is called a "capability" and VMs can only access re= sources via this +capability table. Hence, virtual Gunyah devices are referenced by a "capab= ility IDs" and not a +"resource IDs". A VM can have multiple capability IDs mapping to the same = resource. If 2 VMs have +access to the same resource, they may not be using the same capability ID = to access that resource +since the tables are independent per VM. + +Resource Manager +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The resource manager (RM) is a privileged application VM supporting the Gu= nyah Hypervisor. +It provides policy enforcement aspects of the virtualization system. The r= esource manager can +be treated as an extension of the Hypervisor but is separated to its own p= artition to ensure +that the hypervisor layer itself remains small and secure and to maintain = a separation of policy +and mechanism in the platform. On arm64, RM runs at NS-EL1 similar to othe= r virtual machines. + +Communication with the resource manager from each guest VM happens with me= ssage-queue.rst. Details +about the specific messages can be found in drivers/virt/gunyah/rsc_mgr.c + +:: + + +-------+ +--------+ +--------+ + | RM | | VM_A | | VM_B | + +-.-.-.-+ +---.----+ +---.----+ + | | | | + +-.-.-----------.------------.----+ + | | \=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D/ | | + | \=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D/ | + | Gunyah | + +---------------------------------+ + +The source for the resource manager is available at https://github.com/qui= c/gunyah-resource-manager. + +The resource manager provides the following features: + +- VM lifecycle management: allocating a VM, starting VMs, destruction of V= Ms +- VM access control policy, including memory sharing and lending +- Interrupt routing configuration +- Forwarding of system-level events (e.g. VM shutdown) to owner VM + +When booting a virtual machine which uses a devicetree, resource manager o= verlays a +/hypervisor node. This node can let Linux know it is running as a Gunyah g= uest VM, +how to communicate with resource manager, and basic description and capabi= lities 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/vi= rt/gunyah/message-queue.rst new file mode 100644 index 000000000000..e130f124ed52 --- /dev/null +++ b/Documentation/virt/gunyah/message-queue.rst @@ -0,0 +1,52 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Message Queues +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Message queue is a simple low-capacity IPC channel between two VMs. It is +intended for sending small control and configuration messages. Each message +queue object is unidirectional, so a full-duplex IPC channel requires a pa= ir of +objects. + +Messages can be up to 1024 bytes in length. Longer messages require a furt= her +protocol on top of the message queue messages themselves. For instance, co= mmunication +with the resource manager adds a header field for sending longer messages = via multiple +message fragments. + +The diagram below shows how message queue works. A typical configuration i= nvolves +2 message queues. Message queue 1 allows VM_A to send messages to VM_B. Me= ssage +queue 2 allows VM_B to send messages to VM_A. + +1. VM_A sends a message of up to 1024 bytes in length. It raises a hyperca= ll + with the message to inform the hypervisor to add the message to + message queue 1's queue. +2. Gunyah raises the corresponding interrupt for VM_B when any of these ha= ppens: + a. gh_msgq_send has PUSH flag. Queue is immediately flushed. This is th= e typical case. + b. Explicility with gh_msgq_push command from VM_A. + c. Message queue has reached a threshold depth. +3. VM_B calls gh_msgq_recv and Gunyah copies message to requested buffer. + +For VM_B to send a message to VM_A, the process is identical, except that = hypercalls +reference message queue 2's capability ID. + +:: + + +---------------+ +-----------------+ +-------------= --+ + | VM_A | |Gunyah hypervisor| | VM_B = | + | | | | | = | + | | | | | = | + | | Tx | | | = | + | |-------->| | Rx vIRQ | = | + |gh_msgq_send() | Tx vIRQ |Message queue 1 |-------->|gh_msgq_recv(= ) | + | |<------- | | | = | + | | | | | = | + | Message Queue | | | | Message Queu= e | + | driver | | | | driver = | + | | | | | = | + | | | | | = | + | | | | Tx | = | + | | Rx vIRQ | |<--------| = | + |gh_msgq_recv() |<--------|Message queue 2 | Tx vIRQ |gh_msgq_send(= ) | + | | | |-------->| = | + | | | | | = | + | | | | | = | + +---------------+ +-----------------+ +-------------= --+ diff --git a/Documentation/virt/index.rst b/Documentation/virt/index.rst index 2f1cffa87b1b..418d540f5484 100644 --- a/Documentation/virt/index.rst +++ b/Documentation/virt/index.rst @@ -15,6 +15,7 @@ Linux Virtualization Support acrn/index coco/sev-guest hyperv/index + gunyah/index =20 .. only:: html and subproject =20 diff --git a/MAINTAINERS b/MAINTAINERS index f5ca4aefd184..e88ebb7cbcb8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8880,6 +8880,13 @@ L: linux-efi@vger.kernel.org S: Maintained F: block/partitions/efi.* =20 +GUNYAH HYPERVISOR DRIVER +M: Elliot Berman +M: Murali Nalajala +L: linux-arm-msm@vger.kernel.org +S: Supported +F: Documentation/virt/gunyah/ + HABANALABS PCI DRIVER M: Oded Gabbay S: Supported --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C6EEC6FA96 for ; Wed, 28 Sep 2022 20:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234633AbiI1UAl (ORCPT ); Wed, 28 Sep 2022 16:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234645AbiI1UAP (ORCPT ); Wed, 28 Sep 2022 16:00:15 -0400 X-Greylist: delayed 123 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 28 Sep 2022 12:59:30 PDT Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28078218; Wed, 28 Sep 2022 12:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1664395171; x=1695931171; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NLGN8Q6mrtAe+VsUYecER/Bp3qKDihlyPHUb7UXcy2E=; b=sMVKqJA3yN5gqeaHDzBhPxrjQRfUNs9M2ZqhsVfwupCEPerifZDEJBgx +nPSVPTyDFVHlQiVa3aLGUwLfVMAJv14em6y3Cjqm7sddhx7MMx58q8R2 68/BPpEaNVI/V2+6dmhym+vOAyJB6xsp6KAx6E0OJWCDzD+W+r/VzAG0m s=; Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 28 Sep 2022 12:57:27 -0700 X-QCInternal: smtphost Received: from nasanex01b.na.qualcomm.com ([10.46.141.250]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 12:57:25 -0700 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.986.29; Wed, 28 Sep 2022 12:57:24 -0700 From: Elliot Berman To: Bjorn Andersson , Rob Herring , Krzysztof Kozlowski CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Jonathan Corbet , Will Deacon , Catalin Marinas , Arnd Bergmann , Greg Kroah-Hartman , , , , Subject: [PATCH v4 02/14] dt-bindings: Add binding for gunyah hypervisor Date: Wed, 28 Sep 2022 12:56:21 -0700 Message-ID: <20220928195633.2348848-3-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When Linux is booted as a guest under the Gunyah hypervisor, 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. Signed-off-by: Elliot Berman --- .../bindings/firmware/gunyah-hypervisor.yaml | 87 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 88 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/gunyah-hyper= visor.yaml diff --git a/Documentation/devicetree/bindings/firmware/gunyah-hypervisor.y= aml b/Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml new file mode 100644 index 000000000000..f0a14101e2fd --- /dev/null +++ b/Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml @@ -0,0 +1,87 @@ +# 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: + - Murali Nalajala + - Elliot Berman + +description: |+ + On systems which support devicetree, Gunyah generates and overlays a dev= iceetree overlay which + describes the basic configuration of the hypervisor. Virtual machines us= e this information to determine + the capability IDs of the message queues used to communicate with the Gu= nyah Resource Manager. + See also: https://github.com/quic/gunyah-resource-manager/blob/develop/s= rc/vm_creation/dto_construct.c + +properties: + compatible: + items: + - const: gunyah-hypervisor-1.0 + - 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: + items: + - const: gunyah-resource-manager-1-0 + - 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 =3D <2>; + #size-cells =3D <0>; + compatible =3D "gunyah-hypervisor-1.0", "gunyah-hypervisor"; + + gunyah-resource-mgr@0 { + compatible =3D "gunyah-resource-manager-1-0", "gunyah-resource= -manager"; + interrupts =3D , /* TX full IR= Q */ + ; /* RX empty IRQ= */ + reg =3D <0x00000000 0x00000000>, <0x00000000 0x00000001>; + /* TX, RX cap ids */ + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index e88ebb7cbcb8..5b6b6f25c604 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8885,6 +8885,7 @@ M: Elliot Berman M: Murali Nalajala L: linux-arm-msm@vger.kernel.org S: Supported +F: Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml F: Documentation/virt/gunyah/ =20 HABANALABS PCI DRIVER --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65918C6FA90 for ; Wed, 28 Sep 2022 19:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234502AbiI1T6K (ORCPT ); Wed, 28 Sep 2022 15:58:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234459AbiI1T5m (ORCPT ); Wed, 28 Sep 2022 15:57:42 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 326E65509D; Wed, 28 Sep 2022 12:57:40 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SJSpUo027441; Wed, 28 Sep 2022 19:57:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=hT8omuFurzv/CTps/1Sv9pKKfuVW13cQYKJD7CV8nPQ=; b=HZesoL9iBakcnPeGIEciCPY3+lURdVLBSeuBW6/4TXKTHnF3V+8NBgiY1WmPyWvHA3hT wxQ6RKbqXbA+BAt078iV7+UrphczN/aXD+19sqfSxW2YwqxDAnanTs8hD8QjYkxWLdek RkIF0eOwmV7Y99QZ5euFnto+qDdAPnhsJyuYwm9ZwkjJNhjA9qs2uBMPfl5F3jSGIPwE CSkOXIzpAdqDOY8ZH/iRnaMrANDhaQ8IVtWs9+2WqjMIEy3UJMv7mokDVbook5M1to/K kGZOowA9kzlgnN6imo0s50LMR1JZP2TZMswAZkdZczbvpodoc87Dw7X+cKG8FbJCwtvm VA== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvpuv98vn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:27 +0000 Received: from nasanex01b.na.qualcomm.com (corens_vlan604_snip.qualcomm.com [10.53.140.1]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 28SJvQTr022169 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:26 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.986.29; Wed, 28 Sep 2022 12:57:25 -0700 From: Elliot Berman To: Bjorn Andersson , Arnd Bergmann CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Greg Kroah-Hartman" , , , , Subject: [PATCH v4 03/14] gunyah: Common types and error codes for Gunyah hypercalls Date: Wed, 28 Sep 2022 12:56:22 -0700 Message-ID: <20220928195633.2348848-4-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: 2rzRnaorIfSriGmy5WyaQYhZfkvV0DW0 X-Proofpoint-ORIG-GUID: 2rzRnaorIfSriGmy5WyaQYhZfkvV0DW0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_09,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=891 spamscore=0 suspectscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280119 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add architecture-independent standard error codes, types, and macros for Gunyah hypercalls. Signed-off-by: Elliot Berman --- MAINTAINERS | 1 + include/asm-generic/gunyah.h | 74 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 include/asm-generic/gunyah.h diff --git a/MAINTAINERS b/MAINTAINERS index 5b6b6f25c604..31bda0197f9a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8887,6 +8887,7 @@ L: linux-arm-msm@vger.kernel.org S: Supported F: Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml F: Documentation/virt/gunyah/ +F: include/asm-generic/gunyah.h =20 HABANALABS PCI DRIVER M: Oded Gabbay diff --git a/include/asm-generic/gunyah.h b/include/asm-generic/gunyah.h new file mode 100644 index 000000000000..64a02dd3b5ad --- /dev/null +++ b/include/asm-generic/gunyah.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _ASM_GUNYAH_H +#define _ASM_GUNYAH_H + +#include +#include + +/* Common Gunyah macros */ +#define GH_CAPID_INVAL U64_MAX +#define GH_VMID_ROOT_VM 0xff + +#define GH_ERROR_OK 0 + +#define GH_ERROR_UNIMPLEMENTED -1 +#define GH_ERROR_RETRY -2 + +#define GH_ERROR_ARG_INVAL 1 +#define GH_ERROR_ARG_SIZE 2 +#define GH_ERROR_ARG_ALIGN 3 + +#define GH_ERROR_NOMEM 10 + +#define GH_ERROR_ADDR_OVFL 20 +#define GH_ERROR_ADDR_UNFL 21 +#define GH_ERROR_ADDR_INVAL 22 + +#define GH_ERROR_DENIED 30 +#define GH_ERROR_BUSY 31 +#define GH_ERROR_IDLE 32 + +#define GH_ERROR_IRQ_BOUND 40 +#define GH_ERROR_IRQ_UNBOUND 41 + +#define GH_ERROR_CSPACE_CAP_NULL 50 +#define GH_ERROR_CSPACE_CAP_REVOKED 51 +#define GH_ERROR_CSPACE_WRONG_OBJ_TYPE 52 +#define GH_ERROR_CSPACE_INSUF_RIGHTS 53 +#define GH_ERROR_CSPACE_FULL 54 + +#define GH_ERROR_MSGQUEUE_EMPTY 60 +#define GH_ERROR_MSGQUEUE_FULL 61 + +static inline int gh_remap_error(int gh_error) +{ + switch (gh_error) { + case GH_ERROR_OK: + return 0; + case GH_ERROR_NOMEM: + return -ENOMEM; + case GH_ERROR_DENIED: + case GH_ERROR_CSPACE_CAP_NULL: + case GH_ERROR_CSPACE_CAP_REVOKED: + case GH_ERROR_CSPACE_WRONG_OBJ_TYPE: + case GH_ERROR_CSPACE_INSUF_RIGHTS: + case GH_ERROR_CSPACE_FULL: + return -EACCES; + case GH_ERROR_BUSY: + case GH_ERROR_IDLE: + return -EBUSY; + case GH_ERROR_IRQ_BOUND: + case GH_ERROR_IRQ_UNBOUND: + case GH_ERROR_MSGQUEUE_FULL: + case GH_ERROR_MSGQUEUE_EMPTY: + return -EPERM; + default: + return -EINVAL; + } +} + +#endif --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F19E0C6FA98 for ; Wed, 28 Sep 2022 19:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234540AbiI1T5v (ORCPT ); Wed, 28 Sep 2022 15:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234494AbiI1T5m (ORCPT ); Wed, 28 Sep 2022 15:57:42 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5465A543FF; Wed, 28 Sep 2022 12:57:40 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SIswDo014804; Wed, 28 Sep 2022 19:57:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=NdBMegGfQRT3NVnpSimV4eMtuPXioAvn9GAQ6vw5iwE=; b=ERLMeh/ZTmpvYaqxXzeHc3+vR31zxhuuIfTo3mKl+MRXnM2X9NFiQi8z4MuECHIxDvH8 mY4NrC2FMN49JPsHqcYW9uFcwWukojAnHUF1xi2ZjNc21E8EH5wN4DB6vqkV1h4znFv6 uD7AxuqzBxhGX/N+9EzCHQahFCp6F58QmQjJLdsVRhmaRKC0zv7p23LyO/JzqVg8Pa7z rZe4rBOVsXC1YmXtr38JAAgvEQH8lvteFCpqbjfS1djcu1xu7Ukrnu71eT1Vw164pdF3 7wCWYphetNg/uUzSZ6l+zV41TNOopKv+7FOjUefChRvmUvRrpxjAzuWfJ8NIlUFteXJ9 aw== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvuxtr5u0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:27 +0000 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 28SJvRUO007498 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:27 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.986.29; Wed, 28 Sep 2022 12:57:26 -0700 From: Elliot Berman To: Bjorn Andersson , Mark Rutland , Lorenzo Pieralisi , "Sudeep Holla" CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Marc Zyngier , "Rob Herring" , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Arnd Bergmann" , Greg Kroah-Hartman , , , , Subject: [PATCH v4 04/14] arm64: smccc: Include alternative-macros.h Date: Wed, 28 Sep 2022 12:56:23 -0700 Message-ID: <20220928195633.2348848-5-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: QyF3LfcdhOkgXtEfd3BFQGpnmiSjA84g X-Proofpoint-ORIG-GUID: QyF3LfcdhOkgXtEfd3BFQGpnmiSjA84g X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_09,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxlogscore=697 clxscore=1015 phishscore=0 suspectscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280119 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix build error when CONFIG_ARM64_SVE is selected and asm/alternative-macros.h wasn't implicitly included by another header. Fixes: cfa7ff959a78 ("arm64: smccc: Support SMCCC v1.3 SVE register saving = hint") Signed-off-by: Elliot Berman --- include/linux/arm-smccc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 220c8c60e021..6a627cdbbdec 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -383,6 +383,7 @@ asmlinkage void __arm_smccc_hvc(unsigned long a0, unsig= ned long a1, =20 /* nVHE hypervisor doesn't have a current thread so needs separate checks = */ #if defined(CONFIG_ARM64_SVE) && !defined(__KVM_NVHE_HYPERVISOR__) +#include =20 #define SMCCC_SVE_CHECK ALTERNATIVE("nop \n", "bl __arm_smccc_sve_check \= n", \ ARM64_SVE) --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A33DC6FA82 for ; Wed, 28 Sep 2022 19:58:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234624AbiI1T54 (ORCPT ); Wed, 28 Sep 2022 15:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234490AbiI1T5m (ORCPT ); Wed, 28 Sep 2022 15:57:42 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35C6353000; Wed, 28 Sep 2022 12:57:40 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SIslci013958; Wed, 28 Sep 2022 19:57:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=sIeIv2GHhdIaUzuwyuy1aRskVdv99fEUoIF3oD08GRw=; b=LNTlZNG9EQNrCY8dvx5e2vPItTfWN/MmN/NAf859JPYVyjxq7HwHLqT/KciEYzV+5+Yr dCqatfolOrbXhQzxzvfImD7TCZl3+qx2So/0w7Xo7pWfrwJkuZFjhqmpoQKF4kerbIyQ bSsP6jS8r06LpOP+yFa0U8BjpB8oxX4/ZYZdpMljKh3xXqbbtKf5cSumtFjk+pP7l5SZ UAVjFcf8gNQmDSeQawVdf6h0xnc5/ixQUa8oTJhEXvuCHdlOabcxB76USlRIuTsfnQ5P vjN8MbpoBtkOfPA+kuMfy8h2rnkK9bCXSULvJo5FvsaJFGjDDWsfS+QQ7eaJiMytJ+/O Vw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvuxtr5u1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:28 +0000 Received: from nasanex01b.na.qualcomm.com (corens_vlan604_snip.qualcomm.com [10.53.140.1]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 28SJvRht022177 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:27 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.986.29; Wed, 28 Sep 2022 12:57:26 -0700 From: Elliot Berman To: Bjorn Andersson , Mark Rutland , Lorenzo Pieralisi , "Sudeep Holla" , Arnd Bergmann CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Marc Zyngier , "Rob Herring" , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Greg Kroah-Hartman" , , , , Subject: [PATCH v4 05/14] virt: gunyah: Add hypercalls to identify Gunyah Date: Wed, 28 Sep 2022 12:56:24 -0700 Message-ID: <20220928195633.2348848-6-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: wTHt_ZghDsNr31n_AFi3DUZmuIFH67zo X-Proofpoint-ORIG-GUID: wTHt_ZghDsNr31n_AFi3DUZmuIFH67zo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_09,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 suspectscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280119 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add hypercalls to identify when Linux is running 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. Signed-off-by: Elliot Berman --- MAINTAINERS | 2 + arch/arm64/Kbuild | 1 + arch/arm64/gunyah/Makefile | 2 + arch/arm64/gunyah/hypercall.c | 71 +++++++++++++++++++++++++++++++++++ drivers/virt/Kconfig | 2 + drivers/virt/gunyah/Kconfig | 13 +++++++ include/asm-generic/gunyah.h | 36 ++++++++++++++++++ 7 files changed, 127 insertions(+) create mode 100644 arch/arm64/gunyah/Makefile create mode 100644 arch/arm64/gunyah/hypercall.c create mode 100644 drivers/virt/gunyah/Kconfig diff --git a/MAINTAINERS b/MAINTAINERS index 31bda0197f9a..feafac12db35 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8887,6 +8887,8 @@ 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/asm-generic/gunyah.h =20 HABANALABS PCI DRIVER diff --git a/arch/arm64/Kbuild b/arch/arm64/Kbuild index 5bfbf7d79c99..fbcde0d5cec8 100644 --- a/arch/arm64/Kbuild +++ b/arch/arm64/Kbuild @@ -4,6 +4,7 @@ obj-$(CONFIG_KVM) +=3D kvm/ obj-$(CONFIG_XEN) +=3D xen/ obj-$(subst m,y,$(CONFIG_HYPERV)) +=3D hyperv/ obj-$(CONFIG_CRYPTO) +=3D crypto/ +obj-$(CONFIG_GUNYAH) +=3D gunyah/ =20 # for cleaning subdir- +=3D boot diff --git a/arch/arm64/gunyah/Makefile b/arch/arm64/gunyah/Makefile new file mode 100644 index 000000000000..f71a9533c266 --- /dev/null +++ b/arch/arm64/gunyah/Makefile @@ -0,0 +1,2 @@ +obj-$(CONFIG_GUNYAH) +=3D gunyah_hypercall.o +gunyah_hypercall-y +=3D hypercall.o diff --git a/arch/arm64/gunyah/hypercall.c b/arch/arm64/gunyah/hypercall.c new file mode 100644 index 000000000000..5b08c9d80de0 --- /dev/null +++ b/arch/arm64/gunyah/hypercall.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include + +#define GH_CALL_TYPE_PLATFORM_CALL 0 +#define GH_CALL_TYPE_HYPERCALL 2 +#define GH_CALL_TYPE_SERVICE 3 +#define GH_CALL_TYPE_SHIFT 14 +#define GH_CALL_FUNCTION_NUM_MASK 0x3fff + +#define GH_SERVICE(fn) ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_= SMC_32, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + (GH_CALL_TYPE_SERVICE << GH_CALL_TYPE_SHIFT) \ + | ((fn) & GH_CALL_FUNCTION_NUM_MASK)) + +#define GH_HYPERCALL_CALL_UID GH_SERVICE(0x3f01) + +#define GH_HYPERCALL(fn) ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC= _SMC_64, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + (GH_CALL_TYPE_HYPERCALL << GH_CALL_TYPE_SHIFT) \ + | ((fn) & GH_CALL_FUNCTION_NUM_MASK)) + +#define GH_HYPERCALL_HYP_IDENTIFY GH_HYPERCALL(0x0000) + +/** + * gh_hypercall_get_uid() - Returns a UID when running under a Gunyah hype= rvisor. + * @uid: An array of 4 u32's (u32 uid[4];) + * + * The UID will be either QC_HYP_UID or GUNYAH_UID defined in include/asm-= generic/gunyah.h. + * QC_HYP_UID is returned on platforms using Qualcomm's version of Gunyah. + * GUNYAH_UID is returned on platforms using open source version of Gunyah. + * If the uid is not one of the above two UIDs, then it is assumed that th= e hypervisor or firmware + * is not Gunyah. + */ +void gh_hypercall_get_uid(u32 *uid) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GH_HYPERCALL_CALL_UID, &res); + + uid[0] =3D res.a0; + uid[1] =3D res.a1; + uid[2] =3D res.a2; + uid[3] =3D res.a3; +} +EXPORT_SYMBOL_GPL(gh_hypercall_get_uid); + +/** + * gh_hypercall_hyp_identify() - Returns build information and feature fla= gs supported by Gunyah. + * @hyp_identify: filled by the hypercall with the API info and feature fl= ags. + */ +void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_= identity) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GH_HYPERCALL_HYP_IDENTIFY, &res); + + hyp_identity->api_info =3D res.a0; + hyp_identity->flags[0] =3D res.a1; + hyp_identity->flags[1] =3D res.a2; + hyp_identity->flags[2] =3D res.a3; +} +EXPORT_SYMBOL_GPL(gh_hypercall_hyp_identify); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls"); diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index 87ef258cec64..c39409b69d01 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -52,4 +52,6 @@ source "drivers/virt/coco/efi_secret/Kconfig" =20 source "drivers/virt/coco/sev-guest/Kconfig" =20 +source "drivers/virt/gunyah/Kconfig" + endif diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig new file mode 100644 index 000000000000..7ac917e0aa3f --- /dev/null +++ b/drivers/virt/gunyah/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config GUNYAH + tristate "Gunyah Virtualization drivers" + depends on ARM64 + select AUXILIARY_BUS + help + The Gunyah drivers are the helper interfaces that runs 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/asm-generic/gunyah.h b/include/asm-generic/gunyah.h index 64a02dd3b5ad..86eb59e203ef 100644 --- a/include/asm-generic/gunyah.h +++ b/include/asm-generic/gunyah.h @@ -71,4 +71,40 @@ static inline int gh_remap_error(int gh_error) } } =20 +#define QC_HYP_UID0 0x19bd54bd +#define QC_HYP_UID1 0x0b37571b +#define QC_HYP_UID2 0x946f609b +#define QC_HYP_UID3 0x54539de6 + +#define GUNYAH_UID0 0x673d5f14 +#define GUNYAH_UID1 0x9265ce36 +#define GUNYAH_UID2 0xa4535fdb +#define GUNYAH_UID3 0xc1d58fcd + +#define gh_uid_matches(prefix, uid) \ + ((uid)[0] =3D=3D prefix ## _UID0 && (uid)[1] =3D=3D prefix ## _UID1 && \ + (uid)[2] =3D=3D prefix ## _UID2 && (uid)[3] =3D=3D prefix ## _UID3) + +#define GH_API_INFO_API_VERSION(x) (((x) >> 0) & 0x3fff) +#define GH_API_INFO_BIG_ENDIAN(x) (((x) >> 14) & 1) +#define GH_API_INFO_IS_64BIT(x) (((x) >> 15) & 1) +#define GH_API_INFO_VARIANT(x) (((x) >> 56) & 0xff) + +#define GH_IDENTIFY_PARTITION_CSPACE(flags) (((flags)[0] >> 0) & 1) +#define GH_IDENTIFY_DOORBELL(flags) (((flags)[0] >> 1) & 1) +#define GH_IDENTIFY_MSGQUEUE(flags) (((flags)[0] >> 2) & 1) +#define GH_IDENTIFY_VIC(flags) (((flags)[0] >> 3) & 1) +#define GH_IDENTIFY_VPM(flags) (((flags)[0] >> 4) & 1) +#define GH_IDENTIFY_VCPU(flags) (((flags)[0] >> 5) & 1) +#define GH_IDENTIFY_MEMEXTENT(flags) (((flags)[0] >> 6) & 1) +#define GH_IDENTIFY_TRACE_CTRL(flags) (((flags)[0] >> 7) & 1) + +struct gh_hypercall_hyp_identify_resp { + u64 api_info; + u64 flags[3]; +}; + +void gh_hypercall_get_uid(u32 *uid); +void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_= identity); + #endif --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90054C32771 for ; Wed, 28 Sep 2022 19:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234727AbiI1T6c (ORCPT ); Wed, 28 Sep 2022 15:58:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234478AbiI1T5o (ORCPT ); Wed, 28 Sep 2022 15:57:44 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2228558C6; Wed, 28 Sep 2022 12:57:42 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SD604K022266; Wed, 28 Sep 2022 19:57:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=Mc1zaz/62brz07fbZELnYixjwK3DmS2fp3SNZl9ly/Y=; b=l/tPT660gQswPBCR4UL8oqsr7DWXDpaFYDYkeYwoKvQVZrWq7fWPPWXZT4Lo4hbVmYQz Bl24bZCFrKf0/wzR8Om5NuFQ6LKK/o9gGhdb7nHZl/4VCveBJ1UbGHBQyXiYZcCLVe0e NrGxjJ/8ToGlFcbMz3c4agI+Ni8Qusqw6All9v2dk1qsq4AWT9OHywaSIQMthVwUjf51 5Xx6teXWQWnw/TzmcVln6KFN6i0Ohp5h2r7hSxfgpK5YdHVgYxkpw6mQ3GcWI7v7dbPF edZH/1whEu0Z/6UaTvqxktVB1evsK3aGyvuhYwfc6DB08kSldhivwgsiGq/+3UekBHwE 4w== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvpuv98vq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:29 +0000 Received: from nasanex01b.na.qualcomm.com (corens_vlan604_snip.qualcomm.com [10.53.140.1]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 28SJvSL4022185 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57: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.986.29; Wed, 28 Sep 2022 12:57:27 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Arnd Bergmann" , Greg Kroah-Hartman , , , , Subject: [PATCH v4 06/14] virt: gunyah: Add sysfs nodes Date: Wed, 28 Sep 2022 12:56:25 -0700 Message-ID: <20220928195633.2348848-7-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: sBgHLd-ejEHFdoHMqrU1Drf8mlhxZz0P X-Proofpoint-ORIG-GUID: sBgHLd-ejEHFdoHMqrU1Drf8mlhxZz0P X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_09,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280119 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add /sys/hypervisor support when detecting that Linux is running in a Gunyah environment. Export the version of Gunyah which is reported via the hyp_identify hypercall. Signed-off-by: Elliot Berman --- .../ABI/testing/sysfs-hypervisor-gunyah | 15 ++++ MAINTAINERS | 1 + drivers/virt/Makefile | 1 + drivers/virt/gunyah/Makefile | 2 + drivers/virt/gunyah/sysfs.c | 71 +++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-hypervisor-gunyah create mode 100644 drivers/virt/gunyah/Makefile create mode 100644 drivers/virt/gunyah/sysfs.c diff --git a/Documentation/ABI/testing/sysfs-hypervisor-gunyah b/Documentat= ion/ABI/testing/sysfs-hypervisor-gunyah new file mode 100644 index 000000000000..7d74e74e9edd --- /dev/null +++ b/Documentation/ABI/testing/sysfs-hypervisor-gunyah @@ -0,0 +1,15 @@ +What: /sys/hypervisor/gunyah/api +Date: October 2022 +KernelVersion: 6.1 +Contact: linux-arm-msm@vger.kernel.org +Description: If running under Gunyah: + The Gunyah API version. + +What: /sys/hypervisor/gunyah/variant +Date: October 2022 +KernelVersion: 6.1 +Contact: linux-arm-msm@vger.kernel.org +Description: If running under Gunyah: + Reports the build variant of Gunyah: + The open source build of Gunyah will report "81". + The Qualcomm build of Gunyah will report "72". diff --git a/MAINTAINERS b/MAINTAINERS index feafac12db35..a26e67ef36b4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8885,6 +8885,7 @@ M: Elliot Berman M: Murali Nalajala L: linux-arm-msm@vger.kernel.org S: Supported +F: Documentation/ABI/testing/sysfs-hypervisor-gunyah F: Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml F: Documentation/virt/gunyah/ F: arch/arm64/gunyah/ diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile index 093674e05c40..10b87f934730 100644 --- a/drivers/virt/Makefile +++ b/drivers/virt/Makefile @@ -11,3 +11,4 @@ obj-$(CONFIG_NITRO_ENCLAVES) +=3D nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) +=3D acrn/ obj-$(CONFIG_EFI_SECRET) +=3D coco/efi_secret/ obj-$(CONFIG_SEV_GUEST) +=3D coco/sev-guest/ +obj-$(CONFIG_GUNYAH) +=3D gunyah/ diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile new file mode 100644 index 000000000000..e15f16c17142 --- /dev/null +++ b/drivers/virt/gunyah/Makefile @@ -0,0 +1,2 @@ +gunyah-y +=3D sysfs.o +obj-$(CONFIG_GUNYAH) +=3D gunyah.o diff --git a/drivers/virt/gunyah/sysfs.c b/drivers/virt/gunyah/sysfs.c new file mode 100644 index 000000000000..ec11510cbece --- /dev/null +++ b/drivers/virt/gunyah/sysfs.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) "gunyah: " fmt + +#include +#include +#include +#include +#include + +static struct gh_hypercall_hyp_identify_resp gunyah_api; + +static ssize_t api_show(struct kobject *kobj, struct kobj_attribute *attr,= char *buffer) +{ + return sysfs_emit(buffer, "%d\n", (int)GH_API_INFO_API_VERSION(gunyah_api= .api_info)); +} +static struct kobj_attribute api_attr =3D __ATTR_RO(api); + +static ssize_t variant_show(struct kobject *kobj, struct kobj_attribute *a= ttr, char *buffer) +{ + return sysfs_emit(buffer, "%d\n", (int)GH_API_INFO_VARIANT(gunyah_api.api= _info)); +} +static struct kobj_attribute variant_attr =3D __ATTR_RO(variant); + +static struct attribute *gunyah_attrs[] =3D { + &api_attr.attr, + &variant_attr.attr, + NULL +}; + +static const struct attribute_group gunyah_group =3D { + .name =3D "gunyah", + .attrs =3D gunyah_attrs, +}; + +static int __init gunyah_init(void) +{ + u32 uid[4]; + + gh_hypercall_get_uid(uid); + + if (!(gh_uid_matches(GUNYAH, uid) || gh_uid_matches(QC_HYP, uid))) + return 0; + + gh_hypercall_hyp_identify(&gunyah_api); + + if (GH_API_INFO_API_VERSION(gunyah_api.api_info) !=3D 1) { + pr_warn("Unrecognized gunyah version: %llu. Currently supported: 1\n", + GH_API_INFO_API_VERSION(gunyah_api.api_info)); + return 0; + } + + pr_notice("Running under Gunyah hypervisor %llx/v%lld\n", + GH_API_INFO_VARIANT(gunyah_api.api_info), + GH_API_INFO_API_VERSION(gunyah_api.api_info)); + + return sysfs_create_group(hypervisor_kobj, &gunyah_group); +} +module_init(gunyah_init); + +static void __exit gunyah_exit(void) +{ + sysfs_remove_group(hypervisor_kobj, &gunyah_group); +} +module_exit(gunyah_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Hypervisor Driver"); --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0719DC04A95 for ; Wed, 28 Sep 2022 19:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234572AbiI1T6N (ORCPT ); Wed, 28 Sep 2022 15:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234497AbiI1T5n (ORCPT ); Wed, 28 Sep 2022 15:57:43 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5C0550A1; Wed, 28 Sep 2022 12:57:42 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SDlEla004280; Wed, 28 Sep 2022 19:57:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=GvXA7z5IQZxKRT0LbI1ydxR1t3A4IO5H0ORgws0t6KQ=; b=IoyTMtYSn54Y2LJWVsB8WOnbZ/0QGYO3Z9npfZ45lEEMqg1myrDcimP/x3erTTxhWBl7 9S3YhH9zeAua+1gaN/793nD9r+lf4/INBuxhDZlDngqrlaFIgwXMumI7JuUvjQsRMmGo GgxvhH3j2eAf+I5uLvg89RlXqFbDjPHMAFhBAMB47Y6WVowy8MjYBatqjCPHfclpl1gC yB2PPY5tsQgaSOa3wV7W0eekosUUHjOg6IXByU4JvDebQ+cuhujEpJ6c8bdU48QhJy+0 t5WoZcPj9sP6v5y8LwoEJALZ3G7SXurrRK1bdhbnEVRnoNAcHBQBgGrceE4DDXdEoEKF Qw== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvpuv98vr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:29 +0000 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 28SJvSUV019815 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57: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.986.29; Wed, 28 Sep 2022 12:57:28 -0700 From: Elliot Berman To: Bjorn Andersson , Jassi Brar CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , , "Mark Rutland" , Lorenzo Pieralisi , Sudeep Holla , "Marc Zyngier" , Rob Herring , "Krzysztof Kozlowski" , Jonathan Corbet , Will Deacon , Catalin Marinas , Arnd Bergmann , Greg Kroah-Hartman , , , , Subject: [PATCH v4 07/14] mailbox: Allow direct registration to a channel Date: Wed, 28 Sep 2022 12:56:26 -0700 Message-ID: <20220928195633.2348848-8-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: AtSF7xU1uKm7v4w687HPjReORu0ZCpua X-Proofpoint-ORIG-GUID: AtSF7xU1uKm7v4w687HPjReORu0ZCpua X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_09,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280119 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Support virtual mailbox controllers and clients which are not platform devices or come from the devicetree by allowing them to match client to channel via some other mechanism. Signed-off-by: Elliot Berman --- drivers/mailbox/mailbox.c | 96 ++++++++++++++++++++++++---------- include/linux/mailbox_client.h | 1 + 2 files changed, 69 insertions(+), 28 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 4229b9b5da98..adf36c05fa43 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -317,6 +317,71 @@ int mbox_flush(struct mbox_chan *chan, unsigned long t= imeout) } EXPORT_SYMBOL_GPL(mbox_flush); =20 +static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *= cl) +{ + struct device *dev =3D cl->dev; + unsigned long flags; + int ret; + + if (chan->cl || !try_module_get(chan->mbox->dev->driver->owner)) { + dev_dbg(dev, "%s: mailbox not free\n", __func__); + return -EBUSY; + } + + spin_lock_irqsave(&chan->lock, flags); + chan->msg_free =3D 0; + chan->msg_count =3D 0; + chan->active_req =3D NULL; + chan->cl =3D cl; + init_completion(&chan->tx_complete); + + if (chan->txdone_method =3D=3D TXDONE_BY_POLL && cl->knows_txdone) + chan->txdone_method =3D TXDONE_BY_ACK; + + spin_unlock_irqrestore(&chan->lock, flags); + + if (chan->mbox->ops->startup) { + ret =3D chan->mbox->ops->startup(chan); + + if (ret) { + dev_err(dev, "Unable to startup the chan (%d)\n", ret); + mbox_free_channel(chan); + return ret; + } + } + + return 0; +} + +/** + * mbox_bind_client - Request a mailbox channel. + * @chan: The mailbox channel to bind the client to. + * @cl: Identity of the client requesting the channel. + * + * The Client specifies its requirements and capabilities while asking for + * a mailbox channel. It can't be called from atomic context. + * The channel is exclusively allocated and can't be used by another + * client before the owner calls mbox_free_channel. + * After assignment, any packet received on this channel will be + * handed over to the client via the 'rx_callback'. + * The framework holds reference to the client, so the mbox_client + * structure shouldn't be modified until the mbox_free_channel returns. + * + * Return: 0 if the channel was assigned to the client successfully. + * <0 for request failure. + */ +int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl) +{ + int ret; + + mutex_lock(&con_mutex); + ret =3D __mbox_bind_client(chan, cl); + mutex_unlock(&con_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(mbox_bind_client); + /** * mbox_request_channel - Request a mailbox channel. * @cl: Identity of the client requesting the channel. @@ -340,7 +405,6 @@ struct mbox_chan *mbox_request_channel(struct mbox_clie= nt *cl, int index) struct mbox_controller *mbox; struct of_phandle_args spec; struct mbox_chan *chan; - unsigned long flags; int ret; =20 if (!dev || !dev->of_node) { @@ -372,33 +436,9 @@ struct mbox_chan *mbox_request_channel(struct mbox_cli= ent *cl, int index) return chan; } =20 - if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { - dev_dbg(dev, "%s: mailbox not free\n", __func__); - mutex_unlock(&con_mutex); - return ERR_PTR(-EBUSY); - } - - spin_lock_irqsave(&chan->lock, flags); - chan->msg_free =3D 0; - chan->msg_count =3D 0; - chan->active_req =3D NULL; - chan->cl =3D cl; - init_completion(&chan->tx_complete); - - if (chan->txdone_method =3D=3D TXDONE_BY_POLL && cl->knows_txdone) - chan->txdone_method =3D TXDONE_BY_ACK; - - spin_unlock_irqrestore(&chan->lock, flags); - - if (chan->mbox->ops->startup) { - ret =3D chan->mbox->ops->startup(chan); - - if (ret) { - dev_err(dev, "Unable to startup the chan (%d)\n", ret); - mbox_free_channel(chan); - chan =3D ERR_PTR(ret); - } - } + ret =3D __mbox_bind_client(chan, cl); + if (ret) + chan =3D ERR_PTR(ret); =20 mutex_unlock(&con_mutex); return chan; diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h index 65229a45590f..734694912ef7 100644 --- a/include/linux/mailbox_client.h +++ b/include/linux/mailbox_client.h @@ -37,6 +37,7 @@ struct mbox_client { void (*tx_done)(struct mbox_client *cl, void *mssg, int r); }; =20 +int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl); struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, const char *name); struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index); --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EA40C04A95 for ; Wed, 28 Sep 2022 20:00:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234672AbiI1UAr (ORCPT ); Wed, 28 Sep 2022 16:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234731AbiI1UAP (ORCPT ); Wed, 28 Sep 2022 16:00:15 -0400 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FC00D76; Wed, 28 Sep 2022 12:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1664395173; x=1695931173; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FiwuO7720y1R53gujahjdqSkYpeyV9KxqW1U8kdCmo0=; b=NLjjYBKTKBe0iUpAmwgJK/4BfyIX7dcRZ2Uo4B638QhkfdujuZAdGSfj nWndqwklt0iWTb6H64v6q2kaidMAYjXW0KWjpVHAdQ2OC1du9uiirFtI0 VFpF9xyeqKDG0CWKgb4kKP34cMOCbRwXxXVrEi+CVTBraGXFh3nBZ1Q9z o=; Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 28 Sep 2022 12:57:29 -0700 X-QCInternal: smtphost Received: from nasanex01b.na.qualcomm.com ([10.46.141.250]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 12:57:29 -0700 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.986.29; Wed, 28 Sep 2022 12:57:28 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Arnd Bergmann" , Greg Kroah-Hartman , , , , Subject: [PATCH v4 08/14] virt: gunyah: msgq: Add hypercalls to send and receive messages Date: Wed, 28 Sep 2022 12:56:27 -0700 Message-ID: <20220928195633.2348848-9-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add hypercalls to send and receive messages on a Gunyah message queue. Signed-off-by: Elliot Berman --- arch/arm64/gunyah/hypercall.c | 33 +++++++++++++++++++++++++++++++++ include/asm-generic/gunyah.h | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/arch/arm64/gunyah/hypercall.c b/arch/arm64/gunyah/hypercall.c index 5b08c9d80de0..042cca31879e 100644 --- a/arch/arm64/gunyah/hypercall.c +++ b/arch/arm64/gunyah/hypercall.c @@ -26,6 +26,8 @@ | ((fn) & GH_CALL_FUNCTION_NUM_MASK)) =20 #define GH_HYPERCALL_HYP_IDENTIFY GH_HYPERCALL(0x0000) +#define GH_HYPERCALL_MSGQ_SEND GH_HYPERCALL(0x001B) +#define GH_HYPERCALL_MSGQ_RECV GH_HYPERCALL(0x001C) =20 /** * gh_hypercall_get_uid() - Returns a UID when running under a Gunyah hype= rvisor. @@ -67,5 +69,36 @@ void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_i= dentify_resp *hyp_identi } EXPORT_SYMBOL_GPL(gh_hypercall_hyp_identify); =20 +int gh_hypercall_msgq_send(u64 capid, size_t size, uintptr_t buff, int tx_= flags, bool *ready) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GH_HYPERCALL_MSGQ_SEND, capid, size, buff, tx_flags, 0,= &res); + + if (res.a0) + return res.a0; + + *ready =3D res.a1; + + return res.a0; +} +EXPORT_SYMBOL_GPL(gh_hypercall_msgq_send); + +int gh_hypercall_msgq_recv(u64 capid, uintptr_t buff, size_t size, size_t = *recv_size, bool *ready) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GH_HYPERCALL_MSGQ_RECV, capid, buff, size, 0, &res); + + if (res.a0) + return res.a0; + + *recv_size =3D res.a1; + *ready =3D res.a2; + + return res.a0; +} +EXPORT_SYMBOL_GPL(gh_hypercall_msgq_recv); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls"); diff --git a/include/asm-generic/gunyah.h b/include/asm-generic/gunyah.h index 86eb59e203ef..43915faea704 100644 --- a/include/asm-generic/gunyah.h +++ b/include/asm-generic/gunyah.h @@ -107,4 +107,9 @@ struct gh_hypercall_hyp_identify_resp { void gh_hypercall_get_uid(u32 *uid); void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_= identity); =20 +#define GH_HYPERCALL_MSGQ_TX_FLAGS_PUSH BIT(0) + +int gh_hypercall_msgq_send(u64 capid, size_t size, uintptr_t buff, int tx_= flags, bool *ready); +int gh_hypercall_msgq_recv(u64 capid, uintptr_t buff, size_t size, size_t = *recv_size, bool *ready); + #endif --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A28E5C04A95 for ; Wed, 28 Sep 2022 19:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234697AbiI1T6V (ORCPT ); Wed, 28 Sep 2022 15:58:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234517AbiI1T5t (ORCPT ); Wed, 28 Sep 2022 15:57:49 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80E3F53D32; Wed, 28 Sep 2022 12:57:45 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SJSpUp027441; Wed, 28 Sep 2022 19:57:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=QcUpNcp8887i1C6G7g+TrpelJvYBOsCpcwgUQd9IaDM=; b=iTfcOhqoL4dH17ZZHvQ1Ov+AgSpa5pn34V00FU1pNsve9QNtOkxtKSHaRaccbzEPNEuP Qnt1pynJ54XLq9rTEXRbybifOKyydXVdWFBMqmBZD10guMq7oRYxUQPTA/aFygyGJnKp HCJMSpYfinHk/g18Ymyi2FDpjaxGtRJV+hTvmMBUyVqcaMBXAjyaFTbuQrYD2GtA7Xnb 2kDIwIwqRlFqGKSyo+DuobWBRT30pwnJ2KA8ZqwJRti84Zce4nKihuqHgEEsHPcgldey GeUi9OBv2/+JlZwi0uVlh+wFpzq63/lLN+XAgFTr1enTySdy8ffq6g+vCj1GUtS8cBcs wg== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvpuv98vs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:30 +0000 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 28SJvUSX007528 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57: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.986.29; Wed, 28 Sep 2022 12:57:29 -0700 From: Elliot Berman To: Bjorn Andersson , Jassi Brar CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , , "Mark Rutland" , Lorenzo Pieralisi , Sudeep Holla , "Marc Zyngier" , Rob Herring , "Krzysztof Kozlowski" , Jonathan Corbet , Will Deacon , Catalin Marinas , Arnd Bergmann , Greg Kroah-Hartman , , , , Subject: [PATCH v4 09/14] mailbox: Add Gunyah message queue mailbox Date: Wed, 28 Sep 2022 12:56:28 -0700 Message-ID: <20220928195633.2348848-10-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: w2iJcoOu3PEWMJh29PG2F0-UngEwGuWk X-Proofpoint-ORIG-GUID: w2iJcoOu3PEWMJh29PG2F0-UngEwGuWk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_09,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280119 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Gunyah message queues are a unidirectional inter-VM pipe for messages up to 1024 bytes. This driver supports pairing a receiver message queue and a transmitter message queue to expose a single mailbox channel. Signed-off-by: Elliot Berman --- MAINTAINERS | 2 + drivers/mailbox/Kconfig | 10 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/gunyah-msgq.c | 232 ++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/Kconfig | 2 + include/linux/gunyah.h | 67 ++++++++++ 6 files changed, 315 insertions(+) create mode 100644 drivers/mailbox/gunyah-msgq.c create mode 100644 include/linux/gunyah.h diff --git a/MAINTAINERS b/MAINTAINERS index a26e67ef36b4..74053d8ff7ea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8889,8 +8889,10 @@ F: Documentation/ABI/testing/sysfs-hypervisor-gunyah F: Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml F: Documentation/virt/gunyah/ F: arch/arm64/gunyah/ +F: drivers/mailbox/gunyah-msgq.c F: drivers/virt/gunyah/ F: include/asm-generic/gunyah.h +F: include/linux/gunyah.h =20 HABANALABS PCI DRIVER M: Oded Gabbay diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 05d6fae800e3..baf9451c5f04 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -41,6 +41,16 @@ config IMX_MBOX help Mailbox implementation for i.MX Messaging Unit (MU). =20 +config GUNYAH_MESSAGE_QUEUES + tristate "Gunyah Message Queue Mailbox" + depends on GUNYAH + help + Mailbox implementation for Gunyah Message Queues. Gunyah message queues + are an IPC mechanism to pass short messages between virtual machines + running under the Gunyah hypervisor. + + Say Y here if you run Linux as a Gunyah virtual machine. + config PLATFORM_MHU tristate "Platform MHU Mailbox" depends on OF diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index fc9376117111..5f929bb55e9a 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -55,6 +55,8 @@ obj-$(CONFIG_MTK_CMDQ_MBOX) +=3D mtk-cmdq-mailbox.o =20 obj-$(CONFIG_ZYNQMP_IPI_MBOX) +=3D zynqmp-ipi-mailbox.o =20 +obj-$(CONFIG_GUNYAH) +=3D gunyah-msgq.o + obj-$(CONFIG_SUN6I_MSGBOX) +=3D sun6i-msgbox.o =20 obj-$(CONFIG_SPRD_MBOX) +=3D sprd-mailbox.o diff --git a/drivers/mailbox/gunyah-msgq.c b/drivers/mailbox/gunyah-msgq.c new file mode 100644 index 000000000000..359f682d101c --- /dev/null +++ b/drivers/mailbox/gunyah-msgq.c @@ -0,0 +1,232 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define mbox_chan_to_msgq(chan) (container_of(chan->mbox, struct gunyah_ms= gq, mbox)) + +static inline bool gh_msgq_has_tx(struct gunyah_msgq *msgq) +{ + return msgq->tx_ghrsc.type =3D=3D GUNYAH_RESOURCE_TYPE_MSGQ_TX; +} + +static inline bool gh_msgq_has_rx(struct gunyah_msgq *msgq) +{ + return msgq->rx_ghrsc.type =3D=3D GUNYAH_RESOURCE_TYPE_MSGQ_RX; +} + +static ssize_t __gh_msgq_recv(struct gunyah_msgq *msgq, void *buff, size_t= size, bool *ready) +{ + unsigned long gh_err; + size_t recv_size; + ssize_t ret; + + gh_err =3D gh_hypercall_msgq_recv(msgq->rx_ghrsc.capid, (uintptr_t)buff, = size, + &recv_size, ready); + switch (gh_err) { + case GH_ERROR_OK: + ret =3D recv_size; + break; + case GH_ERROR_MSGQUEUE_EMPTY: + ret =3D -EAGAIN; + *ready =3D false; + break; + default: + ret =3D gh_remap_error(gh_err); + break; + } + + return ret; +} + +static irqreturn_t gh_msgq_rx_irq_handler(int irq, void *data) +{ + struct gunyah_msgq *msgq =3D data; + struct gunyah_msgq_rx_data rx_data; + ssize_t ret; + bool more; + + do { + ret =3D __gh_msgq_recv(msgq, &rx_data.data, sizeof(rx_data.data), &more); + + if (ret >=3D 0) { + rx_data.length =3D ret; + mbox_chan_received_data(gunyah_msgq_chan(msgq), &rx_data); + } else if (ret !=3D -EAGAIN) + pr_warn("Failed to receive data from msgq for %s: %ld\n", + msgq->mbox.dev ? dev_name(msgq->mbox.dev) : "", ret); + } while (ret >=3D 0 && more); + + return IRQ_HANDLED; +} + +static irqreturn_t gh_msgq_tx_irq_handler(int irq, void *data) +{ + struct gunyah_msgq *msgq =3D data; + + mbox_chan_txdone(gunyah_msgq_chan(msgq), 0); + + return IRQ_HANDLED; +} + +static void gh_msgq_txdone_tasklet(unsigned long data) +{ + struct gunyah_msgq *msgq =3D (struct gunyah_msgq *)data; + + mbox_chan_txdone(gunyah_msgq_chan(msgq), msgq->last_status); +} + +static int __gh_msgq_send(struct gunyah_msgq *msgq, void *buff, size_t siz= e, u64 tx_flags) +{ + unsigned long gh_err; + ssize_t ret; + bool ready; + + gh_err =3D gh_hypercall_msgq_send(msgq->tx_ghrsc.capid, size, (uintptr_t)= buff, tx_flags, + &ready); + switch (gh_err) { + case GH_ERROR_OK: + ret =3D !ready; + break; + case GH_ERROR_MSGQUEUE_FULL: + ret =3D -EAGAIN; + break; + default: + /* Not sure how to propagate these out to client. If we get here, nobody= is going + * to trigger a retry + */ + ret =3D gh_remap_error(gh_err); + break; + } + + return ret; +} + +static int gh_msgq_send_data(struct mbox_chan *chan, void *data) +{ + struct gunyah_msgq *msgq =3D mbox_chan_to_msgq(chan); + struct gunyah_msgq_tx_data *msgq_data =3D data; + u64 tx_flags =3D 0; + int ret; + + if (msgq_data->push) + tx_flags |=3D GH_HYPERCALL_MSGQ_TX_FLAGS_PUSH; + + ret =3D __gh_msgq_send(msgq, msgq_data->data, msgq_data->length, tx_flags= ); + + /** + * EAGAIN: message didn't send. + * ret =3D 1: message sent, but now the message queue is full and we can'= t send any more msgs. + * Either way, don't report that this message is done. + */ + if (ret =3D=3D -EAGAIN || ret =3D=3D 1) + return ret; + + /** + * Mailbox framework requires that tx done happens asynchronously to send= ing the message + * IOW, a notification that the message was sent happens after sending th= e message. + * To work around this, defer the txdone to a tasklet. + */ + msgq->last_status =3D ret; + tasklet_schedule(&msgq->txdone_tasklet); + + return 0; +} + +struct mbox_chan_ops gunyah_msgq_ops =3D { + .send_data =3D gh_msgq_send_data, +}; + +/** + * gunyah_msgq_init() - Initialize a Gunyah message queue with an mbox_cli= ent + * @parent: optional, device parent used for the mailbox controller + * @msgq: Pointer to the gunyah_msgq to initialize + * @cl: A mailbox client to bind to the mailbox channel that the message q= ueue creates + * @tx_ghrsc: optional, the transmission side of the message queue + * @rx_ghrsc: optional, the receiving side of the message queue + * + * At least one of tx_ghrsc and rx_ghrsc should be not NULL. Most message = queue use cases come with + * a pair of message queues to facilitiate bidirectional communication. Wh= en tx_ghrsc is set, + * the client can send messages with mbox_send_message(gunyah_msgq_chan(ms= gq), msg). When rx_ghrsc + * is set, the mbox_client should register an .rx_callback() and the messa= ge queue driver will + * push all available messages upon receiving the RX ready interrupt. The = messages should be + * consumed or copied by the client right away as the gunyah_msgq_rx_data = will be replaced/destroyed + * after the callback. + * + * Returns - 0 on success, negative otherwise + */ +int gunyah_msgq_init(struct device *parent, struct gunyah_msgq *msgq, stru= ct mbox_client *cl, + struct gunyah_resource *tx_ghrsc, struct gunyah_resource *rx_ghrsc) +{ + int ret; + + /* Must have at least a tx_ghrsc or rx_ghrsc and that they are the right = device types */ + if ((!tx_ghrsc && !rx_ghrsc) || + (tx_ghrsc && tx_ghrsc->type !=3D GUNYAH_RESOURCE_TYPE_MSGQ_TX) || + (rx_ghrsc && rx_ghrsc->type !=3D GUNYAH_RESOURCE_TYPE_MSGQ_RX)) + return -EINVAL; + + msgq->tx_ghrsc =3D *tx_ghrsc; + msgq->rx_ghrsc =3D *rx_ghrsc; + + msgq->mbox.dev =3D parent; + msgq->mbox.ops =3D &gunyah_msgq_ops; + msgq->mbox.chans =3D kcalloc(1, sizeof(*msgq->mbox.chans), GFP_KERNEL); + msgq->mbox.num_chans =3D 1; + msgq->mbox.txdone_irq =3D true; + + if (gh_msgq_has_tx(msgq)) { + ret =3D request_irq(msgq->tx_ghrsc.irq, gh_msgq_tx_irq_handler, 0, "gh_m= sgq_tx", + msgq); + if (ret) + goto err_chans; + } + + if (gh_msgq_has_rx(msgq)) { + ret =3D request_threaded_irq(msgq->rx_ghrsc.irq, NULL, gh_msgq_rx_irq_ha= ndler, + IRQF_ONESHOT, "gh_msgq_rx", msgq); + if (ret) + goto err_tx_irq; + } + + tasklet_init(&msgq->txdone_tasklet, gh_msgq_txdone_tasklet, (unsigned lon= g)msgq); + + ret =3D mbox_controller_register(&msgq->mbox); + if (ret) + goto err_rx_irq; + + ret =3D mbox_bind_client(gunyah_msgq_chan(msgq), cl); + if (ret) + goto err_mbox; + + return 0; +err_mbox: + mbox_controller_unregister(&msgq->mbox); +err_rx_irq: + if (gh_msgq_has_rx(msgq)) + free_irq(msgq->rx_ghrsc.irq, msgq); +err_tx_irq: + if (gh_msgq_has_tx(msgq)) + free_irq(msgq->tx_ghrsc.irq, msgq); +err_chans: + kfree(msgq->mbox.chans); + return ret; +} +EXPORT_SYMBOL_GPL(gunyah_msgq_init); + +void gunyah_msgq_remove(struct gunyah_msgq *msgq) +{ + if (gh_msgq_has_tx(msgq)) + free_irq(msgq->tx_ghrsc.irq, msgq); + + kfree(msgq->mbox.chans); +} +EXPORT_SYMBOL_GPL(gunyah_msgq_remove); diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig index 7ac917e0aa3f..f4c822a82f1a 100644 --- a/drivers/virt/gunyah/Kconfig +++ b/drivers/virt/gunyah/Kconfig @@ -4,6 +4,8 @@ config GUNYAH tristate "Gunyah Virtualization drivers" depends on ARM64 select AUXILIARY_BUS + select MAILBOX + select GUNYAH_MESSAGE_QUEUES help The Gunyah drivers are the helper interfaces that runs in a guest VM such as basic inter-VM IPC and signaling mechanisms, and higher level diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h new file mode 100644 index 000000000000..d5e80e2defab --- /dev/null +++ b/include/linux/gunyah.h @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _GUNYAH_H +#define _GUNYAH_H + +#include +#include +#include + +#include + +/* Follows resource manager's resource types for VM_GET_HYP_RESOURCES */ +enum gunyah_resource_type { + GUNYAH_RESOURCE_TYPE_BELL_TX =3D 0, + GUNYAH_RESOURCE_TYPE_BELL_RX =3D 1, + GUNYAH_RESOURCE_TYPE_MSGQ_TX =3D 2, + GUNYAH_RESOURCE_TYPE_MSGQ_RX =3D 3, + GUNYAH_RESOURCE_TYPE_VCPU =3D 4, +}; + +struct gunyah_resource { + enum gunyah_resource_type type; + u64 capid; + int irq; +}; + +/** + * Gunyah Message Queues + */ + +#define GH_MSGQ_MAX_MSG_SIZE 1024 + +struct gunyah_msgq_tx_data { + size_t length; + bool push; + char data[]; +}; + +struct gunyah_msgq_rx_data { + size_t length; + char data[GH_MSGQ_MAX_MSG_SIZE]; +}; + +struct gunyah_msgq { + struct gunyah_resource tx_ghrsc; + struct gunyah_resource rx_ghrsc; + + /* msgq private */ + int last_status; + struct mbox_controller mbox; + struct tasklet_struct txdone_tasklet; +}; + + +int gunyah_msgq_init(struct device *parent, struct gunyah_msgq *msgq, stru= ct mbox_client *cl, + struct gunyah_resource *tx_ghrsc, struct gunyah_resource *rx_ghrsc); +void gunyah_msgq_remove(struct gunyah_msgq *msgq); + +static inline struct mbox_chan *gunyah_msgq_chan(struct gunyah_msgq *msgq) +{ + return &msgq->mbox.chans[0]; +} + +#endif --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D419C32771 for ; Wed, 28 Sep 2022 19:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234715AbiI1T62 (ORCPT ); Wed, 28 Sep 2022 15:58:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234400AbiI1T5s (ORCPT ); Wed, 28 Sep 2022 15:57:48 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F24952FD7; Wed, 28 Sep 2022 12:57:46 -0700 (PDT) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SJE33P004332; Wed, 28 Sep 2022 19:57:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=wCgfcmyARAg6EsfpjZdvHcXQvt5yyytPo2ZxS3RYuCs=; b=WDwLa4E0JsZO84LupQs2sM8hSockpV9c4lPuNDD1YFZgt0pCZpDfBv2B4ohguCx+A5rG XGdrPt1zGvCkwMhF3zqU+uisWQ3WGrZl0OdAOCoaAtIwSBvkC8gm4KAkWDOG8ZLSOzne 5/ANbAA+tToRhuZppWA7DPbFvJm+A8s62lFE/0X+UyBvavsUoT5GmbuX3StbzKEidtHl 9VNqqfscVcAvQVIukhyRqinYFKuwbyWq3OlqywEq6qHWNtFnwpqdPvL0mJGcac6GLWRM mV10ysNWLxKiLc6ZFq0yNSPX4y1uHRskkPeQEfMdYYgq4UflvCMcuWRtdKSgMcqZQZYp AQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvu78r4sg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:31 +0000 Received: from nasanex01b.na.qualcomm.com (corens_vlan604_snip.qualcomm.com [10.53.140.1]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 28SJvU9r006633 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57: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.986.29; Wed, 28 Sep 2022 12:57:29 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Arnd Bergmann" , Greg Kroah-Hartman , , , , Subject: [PATCH v4 10/14] gunyah: sysfs: Add node to describe supported features Date: Wed, 28 Sep 2022 12:56:29 -0700 Message-ID: <20220928195633.2348848-11-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: pUJGMMg_9P2Ys9jig0Tv6oGKrlLeQ9XR X-Proofpoint-ORIG-GUID: pUJGMMg_9P2Ys9jig0Tv6oGKrlLeQ9XR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_08,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 mlxlogscore=892 malwarescore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280119 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a sysfs node to list the features that the Gunyah hypervisor and Linux supports. For now, Linux support cspace (capability IDs) and message queues, so only report those.. Signed-off-by: Elliot Berman --- Documentation/ABI/testing/sysfs-hypervisor-gunyah | 15 +++++++++++++++ drivers/virt/gunyah/sysfs.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-hypervisor-gunyah b/Documentat= ion/ABI/testing/sysfs-hypervisor-gunyah index 7d74e74e9edd..6d0cde30355a 100644 --- a/Documentation/ABI/testing/sysfs-hypervisor-gunyah +++ b/Documentation/ABI/testing/sysfs-hypervisor-gunyah @@ -1,3 +1,18 @@ +What: /sys/hypervisor/gunyah/features +Date: October 2022 +KernelVersion: 6.1 +Contact: linux-arm-msm@vger.kernel.org +Description: If running under Gunyah: + Space separated list of features supported by Linux and Gunyah: + "cspace": Gunyah devices + "doorbell": Sending/receiving virtual interrupts via Gunyah doorbells + "message-queue": Sending/receiving messages via Gunyah message queues + "vic": Interrupt lending + "vpm": Virtual platform management + "vcpu": Virtual CPU management + "memextent": Memory lending/management + "trace": Gunyah hypervisor tracing + What: /sys/hypervisor/gunyah/api Date: October 2022 KernelVersion: 6.1 diff --git a/drivers/virt/gunyah/sysfs.c b/drivers/virt/gunyah/sysfs.c index ec11510cbece..f8ec0553c197 100644 --- a/drivers/virt/gunyah/sysfs.c +++ b/drivers/virt/gunyah/sysfs.c @@ -25,9 +25,24 @@ static ssize_t variant_show(struct kobject *kobj, struct= kobj_attribute *attr, c } static struct kobj_attribute variant_attr =3D __ATTR_RO(variant); =20 +static ssize_t features_show(struct kobject *kobj, struct kobj_attribute *= attr, char *buffer) +{ + int len =3D 0; + + if (GH_IDENTIFY_PARTITION_CSPACE(gunyah_api.flags)) + len +=3D sysfs_emit_at(buffer, len, "cspace "); + if (GH_IDENTIFY_MSGQUEUE(gunyah_api.flags)) + len +=3D sysfs_emit_at(buffer, len, "message-queue "); + + len +=3D sysfs_emit_at(buffer, len, "\n"); + return len; +} +static struct kobj_attribute features_attr =3D __ATTR_RO(features); + static struct attribute *gunyah_attrs[] =3D { &api_attr.attr, &variant_attr.attr, + &features_attr.attr, NULL }; =20 --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B351C32771 for ; Wed, 28 Sep 2022 19:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234689AbiI1T6R (ORCPT ); Wed, 28 Sep 2022 15:58:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234320AbiI1T5r (ORCPT ); Wed, 28 Sep 2022 15:57:47 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29DF3558DB; Wed, 28 Sep 2022 12:57:46 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SGCdlQ001950; Wed, 28 Sep 2022 19:57:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=unMlD4k3glmWiC7KJAZ7R85e9qHgxnEIl06jxGVwt1w=; b=JRKczWXgMISi/ekiMO5Wm96cadge05n9OslGd22LnAWbjJiZRampxM/iyasGR2m/D97/ w8xGJth1AFBznF4PO3TAA3iRZImeJ6Ije1vIMNpuhf0GK3GqUMM1AkBHF0qp3QA7HF3H 75BrEXUVnuiECvGNQ0fqOAB9UW5SQ7PaadQ/mVP6Hqnqfi/1jq5aHC5zanCW4taw84Nw U8YFH/1pSQjft+HanfjoHxXa1sihSefTDVEhQ0mISkXlnKy/PA8bQM00E0bDbdiwawmW BnZiNwzH3uOBuDqPTeFkDcP2C6ylgZo0w/ttUzxpGJP8qh0AhMkMq3U4qK5hAJbguKPJ 6A== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvpuv98vu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:32 +0000 Received: from nasanex01b.na.qualcomm.com (corens_vlan604_snip.qualcomm.com [10.53.140.1]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 28SJvV7I022206 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57: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.986.29; Wed, 28 Sep 2022 12:57:30 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Arnd Bergmann" , Greg Kroah-Hartman , , , , Subject: [PATCH v4 11/14] gunyah: rsc_mgr: Add resource manager RPC core Date: Wed, 28 Sep 2022 12:56:30 -0700 Message-ID: <20220928195633.2348848-12-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: V_wWVmn7StmVRN7a6OX59ZSsqty-L0Kx X-Proofpoint-ORIG-GUID: V_wWVmn7StmVRN7a6OX59ZSsqty-L0Kx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_09,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280119 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- MAINTAINERS | 2 +- drivers/virt/gunyah/Kconfig | 20 +- drivers/virt/gunyah/Makefile | 3 + drivers/virt/gunyah/rsc_mgr.c | 608 +++++++++++++++++++++++++++++++++ drivers/virt/gunyah/rsc_mgr.h | 34 ++ include/linux/gunyah_rsc_mgr.h | 26 ++ 6 files changed, 689 insertions(+), 4 deletions(-) create mode 100644 drivers/virt/gunyah/rsc_mgr.c create mode 100644 drivers/virt/gunyah/rsc_mgr.h create mode 100644 include/linux/gunyah_rsc_mgr.h diff --git a/MAINTAINERS b/MAINTAINERS index 74053d8ff7ea..a0cba618e5f6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8892,7 +8892,7 @@ F: arch/arm64/gunyah/ F: drivers/mailbox/gunyah-msgq.c F: drivers/virt/gunyah/ F: include/asm-generic/gunyah.h -F: include/linux/gunyah.h +F: include/linux/gunyah*.h =20 HABANALABS PCI DRIVER M: Oded Gabbay diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig index f4c822a82f1a..78deed3c4562 100644 --- a/drivers/virt/gunyah/Kconfig +++ b/drivers/virt/gunyah/Kconfig @@ -3,9 +3,6 @@ config GUNYAH tristate "Gunyah Virtualization drivers" depends on ARM64 - select AUXILIARY_BUS - select MAILBOX - select GUNYAH_MESSAGE_QUEUES help The Gunyah drivers are the helper interfaces that runs in a guest VM such as basic inter-VM IPC and signaling mechanisms, and higher level @@ -13,3 +10,20 @@ config GUNYAH =20 Say Y/M here to enable the drivers needed to interact in a Gunyah virtual environment. + +if GUNYAH + +config GUNYAH_RESORUCE_MANAGER + tristate "Gunyah Resource Manager" + select MAILBOX + select GUNYAH_MESSAGE_QUEUES + default y + help + The resource manager (RM) is a privileged application VM supporting + the Gunyah Hypervisor. Enable this driver to support communicating + with Gunyah RM. This is typically required for a VM running under + Gunyah wanting to have Gunyah-awareness. + + Say Y/M here if unsure. + +endif diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index e15f16c17142..7c512490f921 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -1,2 +1,5 @@ gunyah-y +=3D sysfs.o obj-$(CONFIG_GUNYAH) +=3D gunyah.o + +gunyah_rsc_mgr-y +=3D rsc_mgr.o +obj-$(CONFIG_GUNYAH_RESORUCE_MANAGER) +=3D 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 000000000000..7f7e89a6436b --- /dev/null +++ b/drivers/virt/gunyah/rsc_mgr.c @@ -0,0 +1,608 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) "gh_rsc_mgr: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rsc_mgr.h" + +/* Resource Manager Header */ +struct gh_rm_rpc_hdr { + u8 version:4, + hdr_words:4; + u8 type:2, + fragments:6; + u16 seq; + u32 msg_id; +} __packed; + +/* Standard reply header */ +struct gh_rm_rpc_reply_hdr { + struct gh_rm_rpc_hdr rpc_hdr; + u32 err_code; +} __packed; + +/* RPC Header versions */ +#define GH_RM_RPC_HDR_VERSION_ONE 0x1 + +/* RPC Header words */ +#define GH_RM_RPC_HDR_WORDS 0x2 + +/* RPC Message types */ +#define GH_RM_RPC_TYPE_CONT 0x0 +#define GH_RM_RPC_TYPE_REQ 0x1 +#define GH_RM_RPC_TYPE_RPLY 0x2 +#define GH_RM_RPC_TYPE_NOTIF 0x3 + +#define GH_RM_MAX_NUM_FRAGMENTS 62 + +#define GH_RM_MAX_MSG_SIZE (GH_MSGQ_MAX_MSG_SIZE - sizeof(struct gh_rm_rpc= _hdr)) + +/** + * struct gh_rm_connection - Represents a complete message from resource m= anager + * @payload: Combined payload of all the fragments (i.e. msg headers strip= ped off). + * @size: Size of the payload. + * @ret: Linux return code, set in case there was an error processing the = connection. + * @msg_id: Message ID from the header. + * @type: GH_RM_RPC_TYPE_RPLY or GH_RM_RPC_TYPE_NOTIF. + * @num_fragments: total number of fragments expected to be received for t= his connection. + * @fragments_recieved: fragments received so far. + * @rm_error: For request/reply sequences with standard replies. + * @seq: Sequence ID for the main message. + */ +struct gh_rm_connection { + void *payload; + size_t size; + int ret; + u32 msg_id; + u8 type; + + u8 num_fragments; + u8 fragments_received; + + /* only for req/reply sequence */ + u32 rm_error; + u16 seq; + struct completion seq_done; +}; + +struct gh_rm_notif_complete { + struct gh_rm_connection *conn; + struct work_struct work; +}; + +struct gh_rsc_mgr { + struct gunyah_msgq msgq; + struct mbox_client msgq_client; + struct gh_rm_connection *active_rx_connection; + int last_tx_ret; + + struct idr call_idr; + struct mutex call_idr_lock; + + struct mutex send_lock; + + struct work_struct recv_work; +}; + +static struct gh_rsc_mgr *__rsc_mgr; +SRCU_NOTIFIER_HEAD_STATIC(gh_rm_notifier); + +static struct gh_rm_connection *gh_rm_alloc_connection(u32 msg_id, u8 type) +{ + struct gh_rm_connection *connection; + + connection =3D kzalloc(sizeof(*connection), GFP_KERNEL); + if (!connection) + return NULL; + + connection->type =3D type; + connection->msg_id =3D msg_id; + + return connection; +} + +/** + * gh_rm_init_connection_payload() - Fills the first message for a connect= ion. + */ +static int gh_rm_init_connection_payload(struct gh_rm_connection *connecti= on, void *msg, + size_t hdr_size, size_t payload_size) +{ + struct gh_rm_rpc_hdr *hdr =3D msg; + size_t max_buf_size; + + connection->num_fragments =3D hdr->fragments; + connection->fragments_received =3D 0; + connection->type =3D hdr->type; + + /* There's not going to be any payload, no need to allocate buffer. */ + if (!payload_size && !connection->num_fragments) + return 0; + + /* + * maximum payload size is GH_MSGQ_MAX_MSG_SIZE - hdr_size + * and can received (hdr->fragments + 1) of those + */ + max_buf_size =3D (GH_MSGQ_MAX_MSG_SIZE - hdr_size) * (hdr->fragments + 1); + + connection->payload =3D kzalloc(max_buf_size, GFP_KERNEL); + if (!connection->payload) + return -ENOMEM; + + memcpy(connection->payload, msg + hdr_size, payload_size); + connection->size =3D payload_size; + return 0; +} + +static void gh_rm_notif_work(struct work_struct *work) +{ + struct gh_rm_notif_complete *notif =3D container_of(work, struct gh_rm_no= tif_complete, work); + struct gh_rm_connection *connection =3D notif->conn; + u32 notif_id =3D connection->msg_id; + struct gh_rm_notification notification =3D { + .buff =3D connection->payload, + .size =3D connection->size, + }; + + srcu_notifier_call_chain(&gh_rm_notifier, notif_id, ¬ification); + + kfree(connection->payload); + kfree(connection); + kfree(notif); +} + +static struct gh_rm_connection *gh_rm_process_notif(struct gh_rsc_mgr *rsc= _mgr, + void *msg, size_t msg_size) +{ + struct gh_rm_rpc_hdr *hdr =3D msg; + struct gh_rm_connection *connection; + + connection =3D gh_rm_alloc_connection(hdr->msg_id, hdr->type); + if (!connection) { + pr_err("Failed to alloc connection for notification, dropping.\n"); + return NULL; + } + + if (gh_rm_init_connection_payload(connection, msg, sizeof(*hdr), msg_size= - sizeof(*hdr))) { + pr_err("Failed to alloc connection buffer for notification, dropping.\n"= ); + kfree(connection); + return NULL; + } + + return connection; +} + +static struct gh_rm_connection *gh_rm_process_rply(struct gh_rsc_mgr *rsc_= mgr, + void *msg, size_t msg_size) +{ + struct gh_rm_rpc_reply_hdr *reply_hdr =3D msg; + struct gh_rm_rpc_hdr *hdr =3D msg; + struct gh_rm_connection *connection; + + if (mutex_lock_interruptible(&rsc_mgr->call_idr_lock)) + return ERR_PTR(-ERESTARTSYS); + + connection =3D idr_find(&rsc_mgr->call_idr, hdr->seq); + mutex_unlock(&rsc_mgr->call_idr_lock); + + if (!connection) { + pr_err("Failed to find connection for sequence %u\n", hdr->seq); + return NULL; + } + if (connection->msg_id !=3D hdr->msg_id) { + pr_err("Reply for sequence %u expected msg_id: %x but got %x\n", hdr->se= q, + connection->msg_id, hdr->msg_id); + /* + * Don't complete connection and error the client, maybe resource manage= r will + * send us the expected reply sequence soon. + */ + return NULL; + } + + if (gh_rm_init_connection_payload(connection, msg, sizeof(*reply_hdr), + msg_size - sizeof(*reply_hdr))) { + pr_err("Failed to alloc connection buffer for sequence %d\n", hdr->seq); + /* Send connection complete and error the client. */ + connection->ret =3D -ENOMEM; + complete(&connection->seq_done); + return NULL; + } + + connection->rm_error =3D reply_hdr->err_code; + return connection; +} + +static void gh_rm_process_cont(struct gh_rm_connection *connection, void *= msg, size_t msg_size) +{ + struct gh_rm_rpc_hdr *hdr =3D msg; + size_t payload_size =3D msg_size - sizeof(*hdr); + + /* + * hdr->fragments and hdr->msg_id preserves the value from first reply or= notif message. + * For sake of sanity, check if it's still intact. + */ + if (connection->msg_id !=3D hdr->msg_id) + pr_warn("Appending mismatched continuation with id %d to connection with= id %d\n", + hdr->msg_id, connection->msg_id); + if (connection->num_fragments !=3D hdr->fragments) + pr_warn("Number of fragments mismatch for seq: %d\n", hdr->seq); + + memcpy(connection->payload + connection->size, msg + sizeof(*hdr), payloa= d_size); + connection->size +=3D payload_size; + connection->fragments_received++; +} + +static bool gh_rm_complete_connection(struct gh_rm_connection *connection) +{ + struct gh_rm_notif_complete *notif_work; + + if (!connection) + return false; + + if (connection->fragments_received !=3D connection->num_fragments) + return false; + + switch (connection->type) { + case GH_RM_RPC_TYPE_RPLY: + complete(&connection->seq_done); + break; + case GH_RM_RPC_TYPE_NOTIF: + notif_work =3D kzalloc(sizeof(*notif_work), GFP_KERNEL); + if (notif_work =3D=3D NULL) + break; + + notif_work->conn =3D connection; + INIT_WORK(¬if_work->work, gh_rm_notif_work); + + schedule_work(¬if_work->work); + break; + default: + pr_err("Invalid message type (%d) received\n", connection->type); + break; + } + + return true; +} + +static void gh_rm_abort_connection(struct gh_rm_connection *connection) +{ + switch (connection->type) { + case GH_RM_RPC_TYPE_RPLY: + connection->ret =3D -EIO; + complete(&connection->seq_done); + break; + case GH_RM_RPC_TYPE_NOTIF: + fallthrough; + default: + kfree(connection->payload); + kfree(connection); + } +} + +static void gh_rm_msgq_rx_data(struct mbox_client *cl, void *mssg) +{ + struct gh_rsc_mgr *rsc_mgr =3D container_of(cl, struct gh_rsc_mgr, msgq_c= lient); + struct gunyah_msgq_rx_data *rx_data =3D mssg; + void *msg =3D rx_data->data; + size_t msg_size =3D rx_data->length; + struct gh_rm_rpc_hdr *hdr; + + if (msg_size <=3D sizeof(struct gh_rm_rpc_hdr)) { + pr_err("Invalid message size received: %ld is too small\n", msg_size); + return; + } + + hdr =3D msg; + switch (hdr->type) { + case GH_RM_RPC_TYPE_NOTIF: + if (rsc_mgr->active_rx_connection) { + /* Not possible per protocol. Do something better than BUG_ON */ + pr_warn("Received start of new notification without finishing existing = message series.\n"); + gh_rm_abort_connection(rsc_mgr->active_rx_connection); + } + rsc_mgr->active_rx_connection =3D gh_rm_process_notif(rsc_mgr, msg, msg_= size); + break; + case GH_RM_RPC_TYPE_RPLY: + if (rsc_mgr->active_rx_connection) { + /* Not possible per protocol. Do something better than BUG_ON */ + pr_warn("Received start of new reply without finishing existing message= series.\n"); + gh_rm_abort_connection(rsc_mgr->active_rx_connection); + } + rsc_mgr->active_rx_connection =3D gh_rm_process_rply(rsc_mgr, msg, msg_s= ize); + break; + case GH_RM_RPC_TYPE_CONT: + if (!rsc_mgr->active_rx_connection) { + pr_warn("Received a continuation message without receiving initial mess= age\n"); + break; + } + gh_rm_process_cont(rsc_mgr->active_rx_connection, msg, msg_size); + break; + default: + pr_err("Invalid message type (%d) received\n", hdr->type); + return; + } + + if (gh_rm_complete_connection(rsc_mgr->active_rx_connection)) + rsc_mgr->active_rx_connection =3D NULL; +} + +static void gh_rm_msgq_tx_done(struct mbox_client *cl, void *mssg, int r) +{ + struct gh_rsc_mgr *rsc_mgr =3D container_of(cl, struct gh_rsc_mgr, msgq_c= lient); + + kfree(mssg); + rsc_mgr->last_tx_ret =3D r; +} + +static int gh_rm_send_request(struct gh_rsc_mgr *rsc_mgr, u32 message_id, + const void *req_buff, size_t req_buff_size, + struct gh_rm_connection *connection) +{ + size_t buff_size_remaining =3D req_buff_size; + const void *req_buff_curr =3D req_buff; + struct gh_rm_rpc_hdr *hdr; + u32 num_fragments =3D 0; + size_t payload_size; + struct gunyah_msgq_tx_data *msg; + int i, ret =3D 0; + + if (req_buff_size > GH_RM_MAX_MSG_SIZE) + num_fragments =3D req_buff_size / GH_RM_MAX_MSG_SIZE; + + if (WARN(num_fragments > GH_RM_MAX_NUM_FRAGMENTS, + "Limit exceeded for the number of fragments: %u\n", num_fragments)) + return -E2BIG; + + /* + * The above calculation also includes the count for the 'request' packet. + * Exclude it as the header needs to fill the num. of fragments to follow. + */ + if (num_fragments) + num_fragments--; + + if (mutex_lock_interruptible(&rsc_mgr->send_lock)) + return -ERESTARTSYS; + + + /* Consider also the 'request' packet for the loop count */ + for (i =3D 0; i <=3D num_fragments; i++) { + if (buff_size_remaining > GH_RM_MAX_MSG_SIZE) { + payload_size =3D GH_RM_MAX_MSG_SIZE; + buff_size_remaining -=3D payload_size; + } else { + payload_size =3D buff_size_remaining; + } + + msg =3D kzalloc(sizeof(*msg) + GH_MSGQ_MAX_MSG_SIZE, GFP_KERNEL); + if (!msg) { + mutex_unlock(&rsc_mgr->send_lock); + return -ENOMEM; + } + + /* Fill header */ + hdr =3D (struct gh_rm_rpc_hdr *)msg->data; + hdr->version =3D GH_RM_RPC_HDR_VERSION_ONE; + hdr->hdr_words =3D GH_RM_RPC_HDR_WORDS; + hdr->type =3D i =3D=3D 0 ? GH_RM_RPC_TYPE_REQ : GH_RM_RPC_TYPE_CONT; + hdr->fragments =3D num_fragments; + hdr->seq =3D connection->seq; + hdr->msg_id =3D message_id; + + /* Copy payload */ + memcpy(msg->data + sizeof(*hdr), req_buff_curr, payload_size); + req_buff_curr +=3D payload_size; + + /* Force the last fragment to immediately alert the receiver */ + msg->push =3D i =3D=3D num_fragments; + msg->length =3D sizeof(*hdr) + payload_size; + + ret =3D mbox_send_message(gunyah_msgq_chan(&rsc_mgr->msgq), msg); + if (ret < 0) { + kfree(msg); + break; + } + + if (rsc_mgr->last_tx_ret) { + ret =3D rsc_mgr->last_tx_ret; + break; + } + } + + mutex_unlock(&rsc_mgr->send_lock); + return ret < 0 ? ret : 0; +} + +/** + * gh_rm_call: Achieve request-response type communication with RPC + * @message_id: The RM RPC message-id + * @req_buff: Request buffer that contains the payload + * @req_buff_size: Total size of the payload + * @resp_buf: Pointer to a response buffer + * @resp_buff_size: Size of the response buffer + * @reply_err_code: Returns Gunyah standard error code for the response + * + * Make a request to the RM-VM and wait for reply back. For a successful + * response, the function returns the payload. The size of the payload is = set in resp_buff_size. + * The resp_buf should be freed by the caller. + * + * Context: Process context. Will sleep waiting for reply. + * Return: >0 is standard reply error from RM. <0 on internal error. + */ +int gh_rm_call(u32 message_id, void *req_buff, size_t req_buff_size, + void **resp_buf, size_t *resp_buff_size) +{ + struct gh_rm_connection *connection; + int ret; + struct gh_rsc_mgr *rsc_mgr =3D __rsc_mgr; + + /* messaged_id 0 is reserved */ + if (!message_id) + return -EINVAL; + + if (!rsc_mgr) + return -EPROBE_DEFER; + + connection =3D gh_rm_alloc_connection(message_id, GH_RM_RPC_TYPE_RPLY); + if (!connection) + return -ENOMEM; + + init_completion(&connection->seq_done); + + /* Allocate a new seq number for this connection */ + if (mutex_lock_interruptible(&rsc_mgr->call_idr_lock)) { + kfree(connection); + return -ERESTARTSYS; + } + connection->seq =3D idr_alloc_cyclic(&rsc_mgr->call_idr, connection, 0, U= 16_MAX, GFP_KERNEL); + mutex_unlock(&rsc_mgr->call_idr_lock); + + /* Send the request to the Resource Manager */ + ret =3D gh_rm_send_request(rsc_mgr, message_id, req_buff, req_buff_size, = connection); + if (ret < 0) + goto out; + + /* Wait for response */ + wait_for_completion(&connection->seq_done); + + if (connection->ret) { + ret =3D connection->ret; + kfree(connection->payload); + goto out; + } + + if (connection->rm_error) { + ret =3D connection->rm_error; + kfree(connection->payload); + goto out; + } + + *resp_buf =3D connection->payload; + *resp_buff_size =3D connection->size; + +out: + mutex_lock(&rsc_mgr->call_idr_lock); + idr_remove(&rsc_mgr->call_idr, connection->seq); + mutex_unlock(&rsc_mgr->call_idr_lock); + + kfree(connection); + return ret; +} + +int gh_rm_register_notifier(struct notifier_block *nb) +{ + return srcu_notifier_chain_register(&gh_rm_notifier, nb); +} +EXPORT_SYMBOL_GPL(gh_rm_register_notifier); + +int gh_rm_unregister_notifier(struct notifier_block *nb) +{ + return srcu_notifier_chain_unregister(&gh_rm_notifier, nb); +} +EXPORT_SYMBOL_GPL(gh_rm_unregister_notifier); + +static int gh_msgq_platform_probe_direction(struct platform_device *pdev, + u8 gh_type, int idx, struct gunyah_resource *ghrsc) +{ + int ret; + struct device_node *node =3D pdev->dev.of_node; + + ghrsc->type =3D gh_type; + + ghrsc->irq =3D platform_get_irq(pdev, idx); + if (ghrsc->irq < 0) { + dev_err(&pdev->dev, "Failed to get irq%d: %d\n", idx, ghrsc->irq); + return ghrsc->irq; + } + + ret =3D of_property_read_u64_index(node, "reg", idx, &ghrsc->capid); + if (ret) { + dev_err(&pdev->dev, "Failed to get capid%d: %d\n", idx, ret); + return ret; + } + + return 0; +} + +static int gh_rm_drv_probe(struct platform_device *pdev) +{ + struct gh_rsc_mgr *rsc_mgr; + struct gunyah_resource tx_ghrsc, rx_ghrsc; + int ret; + + rsc_mgr =3D devm_kzalloc(&pdev->dev, sizeof(*rsc_mgr), GFP_KERNEL); + if (!rsc_mgr) + return -ENOMEM; + platform_set_drvdata(pdev, rsc_mgr); + + mutex_init(&rsc_mgr->call_idr_lock); + idr_init(&rsc_mgr->call_idr); + mutex_init(&rsc_mgr->send_lock); + + ret =3D gh_msgq_platform_probe_direction(pdev, GUNYAH_RESOURCE_TYPE_MSGQ_= TX, 0, &tx_ghrsc); + if (ret) + return ret; + + ret =3D gh_msgq_platform_probe_direction(pdev, GUNYAH_RESOURCE_TYPE_MSGQ_= RX, 1, &rx_ghrsc); + if (ret) + return ret; + + rsc_mgr->msgq_client.dev =3D &pdev->dev; + rsc_mgr->msgq_client.tx_block =3D true; + rsc_mgr->msgq_client.rx_callback =3D gh_rm_msgq_rx_data; + rsc_mgr->msgq_client.tx_done =3D gh_rm_msgq_tx_done; + + ret =3D gunyah_msgq_init(&pdev->dev, &rsc_mgr->msgq, &rsc_mgr->msgq_clien= t, + &tx_ghrsc, &rx_ghrsc); + if (ret) + return ret; + + __rsc_mgr =3D rsc_mgr; + + return 0; +} + +static int gh_rm_drv_remove(struct platform_device *pdev) +{ + struct gh_rsc_mgr *rsc_mgr =3D platform_get_drvdata(pdev); + + __rsc_mgr =3D NULL; + + mbox_free_channel(gunyah_msgq_chan(&rsc_mgr->msgq)); + gunyah_msgq_remove(&rsc_mgr->msgq); + + return 0; +} + +static const struct of_device_id gh_rm_of_match[] =3D { + { .compatible =3D "gunyah-resource-manager" }, + { } +}; +MODULE_DEVICE_TABLE(of, gh_rm_of_match); + +static struct platform_driver gh_rsc_mgr_driver =3D { + .probe =3D gh_rm_drv_probe, + .remove =3D gh_rm_drv_remove, + .driver =3D { + .name =3D "gh_rsc_mgr", + .of_match_table =3D gh_rm_of_match, + }, +}; +module_platform_driver(gh_rsc_mgr_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 000000000000..e4f2499267bf --- /dev/null +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#ifndef __GH_RSC_MGR_PRIV_H +#define __GH_RSC_MGR_PRIV_H + +#include + +/* RM Error codes */ +#define GH_RM_ERROR_OK 0x0 +#define GH_RM_ERROR_UNIMPLEMENTED 0xFFFFFFFF +#define GH_RM_ERROR_NOMEM 0x1 +#define GH_RM_ERROR_NORESOURCE 0x2 +#define GH_RM_ERROR_DENIED 0x3 +#define GH_RM_ERROR_INVALID 0x4 +#define GH_RM_ERROR_BUSY 0x5 +#define GH_RM_ERROR_ARGUMENT_INVALID 0x6 +#define GH_RM_ERROR_HANDLE_INVALID 0x7 +#define GH_RM_ERROR_VALIDATE_FAILED 0x8 +#define GH_RM_ERROR_MAP_FAILED 0x9 +#define GH_RM_ERROR_MEM_INVALID 0xA +#define GH_RM_ERROR_MEM_INUSE 0xB +#define GH_RM_ERROR_MEM_RELEASED 0xC +#define GH_RM_ERROR_VMID_INVALID 0xD +#define GH_RM_ERROR_LOOKUP_FAILED 0xE +#define GH_RM_ERROR_IRQ_INVALID 0xF +#define GH_RM_ERROR_IRQ_INUSE 0x10 +#define GH_RM_ERROR_IRQ_RELEASED 0x11 + +int gh_rm_call(u32 message_id, void *req_buff, size_t req_buff_size, + void **resp_buf, size_t *resp_buff_size); + +#endif diff --git a/include/linux/gunyah_rsc_mgr.h b/include/linux/gunyah_rsc_mgr.h new file mode 100644 index 000000000000..b3b37225b7fb --- /dev/null +++ b/include/linux/gunyah_rsc_mgr.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _GUNYAH_RSC_MGR_H +#define _GUNYAH_RSC_MGR_H + +#include +#include +#include + +#define GH_VMID_INVAL U16_MAX + +/* Gunyah recognizes VMID0 as an alias to the current VM's ID */ +#define GH_VMID_SELF 0 + +struct gh_rm_notification { + const void *buff; + const size_t size; +}; + +int gh_rm_register_notifier(struct notifier_block *nb); +int gh_rm_unregister_notifier(struct notifier_block *nb); + +#endif --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41B86C04A95 for ; Wed, 28 Sep 2022 20:00:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234786AbiI1UA5 (ORCPT ); Wed, 28 Sep 2022 16:00:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234746AbiI1UAS (ORCPT ); Wed, 28 Sep 2022 16:00:18 -0400 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D91B108A; Wed, 28 Sep 2022 12:59:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1664395178; x=1695931178; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2IVpUNrnjO4ojAkyzvSTcWNFQsgnbraPAVbS8edeKUc=; b=C6uHR2ZRtG7biOQ4Ri0TmVpxf/kgVEcsDWR7WtILGHL0rrempJ0yalXl u6X27aQS6lJG5Y01SBaBCaJjPxvWLcE4ud/tYDrUB3vbLLwisCDDzPNU4 NdIcDCmeDP7N9GcE+45i7wLzpQFfj6wz1tgdDdIDt3moHxHX9Uxgjt10U U=; Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 28 Sep 2022 12:57:32 -0700 X-QCInternal: smtphost Received: from nasanex01b.na.qualcomm.com ([10.46.141.250]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 12:57:31 -0700 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.986.29; Wed, 28 Sep 2022 12:57:31 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Arnd Bergmann" , Greg Kroah-Hartman , , , , Subject: [PATCH v4 12/14] gunyah: rsc_mgr: Add RPC for console services Date: Wed, 28 Sep 2022 12:56:31 -0700 Message-ID: <20220928195633.2348848-13-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Gunyah resource manager defines a simple API for virtual machine log sharing with the console service. A VM's own log can be opened by using GH_VMID_SELF. Another VM's log can be accessed via its VMID. Once opened, characters can be written to the log with a write command. Characters are received with resource manager notifications (using ID GH_RM_NOTIF_VM_CONSOLE_CHARS). These high level rpc calls are kept in drivers/virt/gunyah/rsc_mgr_rpc.c. Future RPC calls, e.g. to launch a VM will also be maintained in this file. Signed-off-by: Elliot Berman --- drivers/virt/gunyah/Makefile | 2 +- drivers/virt/gunyah/rsc_mgr.h | 22 +++++ drivers/virt/gunyah/rsc_mgr_rpc.c | 151 ++++++++++++++++++++++++++++++ include/linux/gunyah_rsc_mgr.h | 16 ++++ 4 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 drivers/virt/gunyah/rsc_mgr_rpc.c diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index 7c512490f921..73339ed445b3 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -1,5 +1,5 @@ gunyah-y +=3D sysfs.o obj-$(CONFIG_GUNYAH) +=3D gunyah.o =20 -gunyah_rsc_mgr-y +=3D rsc_mgr.o +gunyah_rsc_mgr-y +=3D rsc_mgr.o rsc_mgr_rpc.o obj-$(CONFIG_GUNYAH_RESORUCE_MANAGER) +=3D gunyah_rsc_mgr.o diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index e4f2499267bf..deb884979209 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -28,6 +28,28 @@ #define GH_RM_ERROR_IRQ_INUSE 0x10 #define GH_RM_ERROR_IRQ_RELEASED 0x11 =20 +/* Message IDs: VM Management */ +#define GH_RM_RPC_VM_GET_VMID 0x56000024 + +/* Message IDs: VM Services */ +#define GH_RM_RPC_VM_CONSOLE_OPEN_ID 0x56000081 +#define GH_RM_RPC_VM_CONSOLE_CLOSE_ID 0x56000082 +#define GH_RM_RPC_VM_CONSOLE_WRITE_ID 0x56000083 +#define GH_RM_RPC_VM_CONSOLE_FLUSH_ID 0x56000084 + +/* Call: CONSOLE_OPEN, CONSOLE_CLOSE, CONSOLE_FLUSH */ +struct gh_vm_console_common_req { + u16 vmid; + u16 reserved0; +} __packed; + +/* Call: CONSOLE_WRITE */ +struct gh_vm_console_write_req { + u16 vmid; + u16 num_bytes; + u8 data[0]; +} __packed; + int gh_rm_call(u32 message_id, void *req_buff, size_t req_buff_size, void **resp_buf, size_t *resp_buff_size); =20 diff --git a/drivers/virt/gunyah/rsc_mgr_rpc.c b/drivers/virt/gunyah/rsc_mg= r_rpc.c new file mode 100644 index 000000000000..8238c6ef301f --- /dev/null +++ b/drivers/virt/gunyah/rsc_mgr_rpc.c @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) "gh_rsc_mgr: " fmt + +#include +#include +#include +#include + +#include "rsc_mgr.h" + +/** + * gh_rm_get_vmid() - Retrieve VMID of this virtual machine + * @vmid: Filled with the VMID of this VM + */ +int gh_rm_get_vmid(u16 *vmid) +{ + void *resp; + size_t resp_size; + int ret; + int payload =3D 0; + + ret =3D gh_rm_call(GH_RM_RPC_VM_GET_VMID, &payload, sizeof(payload), &res= p, &resp_size); + if (ret) + return ret; + + if (resp_size !=3D sizeof(*vmid)) + return -EIO; + *vmid =3D *(u16 *)resp; + kfree(resp); + + return ret; +} + +/** + * gh_rm_console_open() - Open a console with a VM + * @vmid: VMID of the other VM whose console to open. If VMID is GH_VMID_S= ELF, the + * console associated with this VM is opened. + */ +int gh_rm_console_open(u16 vmid) +{ + void *resp; + struct gh_vm_console_common_req req_payload =3D {0}; + size_t resp_size; + int ret; + + req_payload.vmid =3D vmid; + + ret =3D gh_rm_call(GH_RM_RPC_VM_CONSOLE_OPEN_ID, + &req_payload, sizeof(req_payload), + &resp, &resp_size); + kfree(resp); + + if (!ret && resp_size) + pr_warn("Received unexpected payload for CONSOLE_OPEN: %lu\n", resp_size= ); + + return ret; +} +EXPORT_SYMBOL_GPL(gh_rm_console_open); + +/** + * gh_rm_console_close() - Close a console with a VM + * @vmid: The vmid of the vm whose console to close. + */ +int gh_rm_console_close(u16 vmid) +{ + void *resp; + struct gh_vm_console_common_req req_payload =3D {0}; + size_t resp_size; + int ret; + + req_payload.vmid =3D vmid; + + ret =3D gh_rm_call(GH_RM_RPC_VM_CONSOLE_CLOSE_ID, + &req_payload, sizeof(req_payload), + &resp, &resp_size); + kfree(resp); + + if (!ret && resp_size) + pr_warn("Received unexpected payload for CONSOLE_CLOSE: %lu\n", resp_siz= e); + + return ret; +} +EXPORT_SYMBOL_GPL(gh_rm_console_close); + +/** + * gh_rm_console_write() - Write to a VM's console + * @vmid: The vmid of the vm whose console to write to. + * @buf: Buffer to write to the VM's console + * @size: Size of the buffer + */ +int gh_rm_console_write(u16 vmid, const char *buf, size_t size) +{ + void *resp; + struct gh_vm_console_write_req *req_payload; + size_t resp_size; + int ret =3D 0; + size_t req_payload_size =3D sizeof(*req_payload) + size; + + if (size < 1 || size > (U32_MAX - sizeof(*req_payload))) + return -EINVAL; + + req_payload =3D kzalloc(req_payload_size, GFP_KERNEL); + + if (!req_payload) + return -ENOMEM; + + req_payload->vmid =3D vmid; + req_payload->num_bytes =3D size; + memcpy(req_payload->data, buf, size); + + ret =3D gh_rm_call(GH_RM_RPC_VM_CONSOLE_WRITE_ID, + req_payload, req_payload_size, + &resp, &resp_size); + kfree(req_payload); + kfree(resp); + + if (!ret && resp_size) + pr_warn("Received unexpected payload for CONSOLE_WRITE: %lu\n", resp_siz= e); + + return ret; +} +EXPORT_SYMBOL_GPL(gh_rm_console_write); + +/** + * gh_rm_console_flush() - Flush a console with a VM + * @vmid: The vmid of the vm whose console to flush + */ +int gh_rm_console_flush(u16 vmid) +{ + void *resp; + struct gh_vm_console_common_req req_payload =3D {0}; + size_t resp_size; + int ret; + + req_payload.vmid =3D vmid; + + ret =3D gh_rm_call(GH_RM_RPC_VM_CONSOLE_FLUSH_ID, + &req_payload, sizeof(req_payload), + &resp, &resp_size); + kfree(resp); + + if (!ret && resp_size) + pr_warn("Received unexpected payload for CONSOLE_FLUSH: %lu\n", resp_siz= e); + + return ret; +} +EXPORT_SYMBOL_GPL(gh_rm_console_flush); diff --git a/include/linux/gunyah_rsc_mgr.h b/include/linux/gunyah_rsc_mgr.h index b3b37225b7fb..f831ca921c26 100644 --- a/include/linux/gunyah_rsc_mgr.h +++ b/include/linux/gunyah_rsc_mgr.h @@ -23,4 +23,20 @@ struct gh_rm_notification { int gh_rm_register_notifier(struct notifier_block *nb); int gh_rm_unregister_notifier(struct notifier_block *nb); =20 +/* Notification type Message IDs */ +#define GH_RM_NOTIF_VM_CONSOLE_CHARS 0x56100080 + +struct gh_rm_notif_vm_console_chars { + u16 vmid; + u16 num_bytes; + u8 bytes[0]; +} __packed; + +/* RPC Calls */ +int gh_rm_get_vmid(u16 *vmid); +int gh_rm_console_open(u16 vmid); +int gh_rm_console_close(u16 vmid); +int gh_rm_console_write(u16 vmid, const char *buf, size_t size); +int gh_rm_console_flush(u16 vmid); + #endif --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36BBDC04A95 for ; Wed, 28 Sep 2022 20:01:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234805AbiI1UBB (ORCPT ); Wed, 28 Sep 2022 16:01:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234739AbiI1UAR (ORCPT ); Wed, 28 Sep 2022 16:00:17 -0400 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CC4F64DF; Wed, 28 Sep 2022 12:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1664395175; x=1695931175; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6oQz+Ilwb7H/uceQOKMBX7gSuoaNnlVyYZlEI3/uvrQ=; b=aiPeCHsHtkjPsNYRnqcnJT0n4dZ3mHC74j1G/3cO4B9lW90B8itMWJ4b W7VLhKcYLOF5pk6JUmqYpWdXfwVBeSnvo4I42bUZ0990SxH9Zw33Bro4T 8YVLstxbHVtveHTS+jlIk3lfkw4rxMajk4NwI2tleM87aOBoDW+YlnzC+ U=; Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 28 Sep 2022 12:57:32 -0700 X-QCInternal: smtphost Received: from nasanex01b.na.qualcomm.com ([10.46.141.250]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 12:57:32 -0700 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.986.29; Wed, 28 Sep 2022 12:57:31 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Arnd Bergmann" , Greg Kroah-Hartman , , , , Subject: [PATCH v4 13/14] gunyah: rsc_mgr: Add auxiliary devices for console Date: Wed, 28 Sep 2022 12:56:32 -0700 Message-ID: <20220928195633.2348848-14-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Gunyah resource manager exposes a concrete functionalities which complicate a single resource manager driver. Use auxiliary bus to help split high level functions for the resource manager and keep the primary resource manager driver focused on the RPC with RM itself. Delegate Resource Manager's console functionality to the auxiliary bus. Signed-off-by: Elliot Berman --- drivers/virt/gunyah/Kconfig | 1 + drivers/virt/gunyah/rsc_mgr.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig index 78deed3c4562..610c8586005b 100644 --- a/drivers/virt/gunyah/Kconfig +++ b/drivers/virt/gunyah/Kconfig @@ -17,6 +17,7 @@ config GUNYAH_RESORUCE_MANAGER tristate "Gunyah Resource Manager" select MAILBOX select GUNYAH_MESSAGE_QUEUES + select AUXILIARY_BUS default y help The resource manager (RM) is a privileged application VM supporting diff --git a/drivers/virt/gunyah/rsc_mgr.c b/drivers/virt/gunyah/rsc_mgr.c index 7f7e89a6436b..435fe0149915 100644 --- a/drivers/virt/gunyah/rsc_mgr.c +++ b/drivers/virt/gunyah/rsc_mgr.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include =20 @@ -98,6 +99,8 @@ struct gh_rsc_mgr { struct mutex send_lock; =20 struct work_struct recv_work; + + struct auxiliary_device console_adev; }; =20 static struct gh_rsc_mgr *__rsc_mgr; @@ -573,13 +576,31 @@ static int gh_rm_drv_probe(struct platform_device *pd= ev) =20 __rsc_mgr =3D rsc_mgr; =20 + rsc_mgr->console_adev.dev.parent =3D &pdev->dev; + rsc_mgr->console_adev.name =3D "console"; + ret =3D auxiliary_device_init(&rsc_mgr->console_adev); + if (ret) + goto err_msgq; + ret =3D auxiliary_device_add(&rsc_mgr->console_adev); + if (ret) + goto err_console_adev_uninit; + return 0; + +err_console_adev_uninit: + auxiliary_device_uninit(&rsc_mgr->console_adev); +err_msgq: + gunyah_msgq_remove(&rsc_mgr->msgq); + return ret; } =20 static int gh_rm_drv_remove(struct platform_device *pdev) { struct gh_rsc_mgr *rsc_mgr =3D platform_get_drvdata(pdev); =20 + auxiliary_device_delete(&rsc_mgr->console_adev); + auxiliary_device_uninit(&rsc_mgr->console_adev); + __rsc_mgr =3D NULL; =20 mbox_free_channel(gunyah_msgq_chan(&rsc_mgr->msgq)); --=20 2.25.1 From nobody Tue Apr 30 03:36:46 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 219FEC04A95 for ; Wed, 28 Sep 2022 19:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234705AbiI1T6Z (ORCPT ); Wed, 28 Sep 2022 15:58:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234453AbiI1T5t (ORCPT ); Wed, 28 Sep 2022 15:57:49 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D20953D3D; Wed, 28 Sep 2022 12:57:47 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SJqLiP018787; Wed, 28 Sep 2022 19:57:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=8ODXVfRXyvhzhZL3SSFC58yLogbf8HDcBx1jlbfpVSs=; b=TtPRTZSy5qR6mMhRkky6O+hyruZlaDpxpL9JCSq94Hh5eSjyRR6h19jpygpgQdkynGes 0tTnnrDP1sNb4dHbAtRNAMxHeGiikSPp895kMi8XqKpNfjGAEfUVz0+FC8xmcxGaac2x 60iijU8AGEaNj3grOpgqeykCa/zdvbvoSvp5eVU0Qj7cn5rysRdt8PSQ2k3MVK5dFrxP 7ZBGsT71oZF0C2NPG6qLMGdv8TrIrBxCIsxBu+sT7Ct6TZ3xsKOSk5H6MHRBf68RKP9e zMHKiCrPHtXx48t8K4QVvG7iP92otxX1dqfZZ7GSEA0WcjeYKMaNACvMyTdNtmmALF9v EA== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvfp3tk24-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57:34 +0000 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 28SJvXfE026010 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Sep 2022 19:57: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.986.29; Wed, 28 Sep 2022 12:57:32 -0700 From: Elliot Berman To: Bjorn Andersson , Greg Kroah-Hartman , Jiri Slaby CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , Jassi Brar , , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , "Will Deacon" , Catalin Marinas , "Arnd Bergmann" , , , , Subject: [PATCH v4 14/14] tty: gunyah: Add tty console driver for RM Console Services Date: Wed, 28 Sep 2022 12:56:33 -0700 Message-ID: <20220928195633.2348848-15-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220928195633.2348848-1-quic_eberman@quicinc.com> References: <20220928195633.2348848-1-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: eG439zpOQdxTaWMegKMz6AeBzxzceC6X X-Proofpoint-GUID: eG439zpOQdxTaWMegKMz6AeBzxzceC6X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-28_09,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 adultscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209280119 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Gunyah provides a console for each VM using the VM console resource manager APIs. This driver allows console data from other VMs to be accessed via a TTY device and exports a console device to dump Linux's own logs to our console. Signed-off-by: Elliot Berman --- MAINTAINERS | 1 + drivers/tty/Kconfig | 8 + drivers/tty/Makefile | 1 + drivers/tty/gunyah_tty.c | 409 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 419 insertions(+) create mode 100644 drivers/tty/gunyah_tty.c diff --git a/MAINTAINERS b/MAINTAINERS index a0cba618e5f6..e8d4a6d9491a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8890,6 +8890,7 @@ F: Documentation/devicetree/bindings/firmware/gunyah-= hypervisor.yaml F: Documentation/virt/gunyah/ F: arch/arm64/gunyah/ F: drivers/mailbox/gunyah-msgq.c +F: drivers/tty/gunyah_tty.c F: drivers/virt/gunyah/ F: include/asm-generic/gunyah.h F: include/linux/gunyah*.h diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index cc30ff93e2e4..ff86e977f9ac 100644 --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig @@ -380,6 +380,14 @@ config RPMSG_TTY To compile this driver as a module, choose M here: the module will be called rpmsg_tty. =20 +config GUNYAH_CONSOLE + tristate "Gunyah Consoles" + depends on GUNYAH + help + This enables support for console output using Gunyah's Resource Manager= RPC. + This is normally used when a secondary VM which does not have exclusive= access + to a real or virtualized serial device and virtio-console is unavailabl= e. + endif # TTY =20 source "drivers/tty/serdev/Kconfig" diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile index 07aca5184a55..d183fbfd835b 100644 --- a/drivers/tty/Makefile +++ b/drivers/tty/Makefile @@ -27,5 +27,6 @@ obj-$(CONFIG_GOLDFISH_TTY) +=3D goldfish.o obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) +=3D mips_ejtag_fdc.o obj-$(CONFIG_VCC) +=3D vcc.o obj-$(CONFIG_RPMSG_TTY) +=3D rpmsg_tty.o +obj-$(CONFIG_GUNYAH_CONSOLE) +=3D gunyah_tty.o =20 obj-y +=3D ipwireless/ diff --git a/drivers/tty/gunyah_tty.c b/drivers/tty/gunyah_tty.c new file mode 100644 index 000000000000..80a20da11ad0 --- /dev/null +++ b/drivers/tty/gunyah_tty.c @@ -0,0 +1,409 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) "gh_rsc_mgr_console: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The Linux TTY code does not support dynamic addition of tty derived dev= ices so we need to know + * how many tty devices we might need when space is allocated for the tty = device. Since VMs might be + * added/removed dynamically, we need to make sure we have enough allocate= d. + */ +#define RSC_MGR_TTY_ADAPTERS 16 + +/* # of payload bytes that can fit in a 1-fragment CONSOLE_WRITE message */ +#define RM_CONS_WRITE_MSG_SIZE ((1 * (GH_MSGQ_MAX_MSG_SIZE - 8)) - 4) + +struct rm_cons_port { + struct tty_port port; + u16 vmid; + bool open; + unsigned int index; + + DECLARE_KFIFO(put_fifo, char, 1024); + spinlock_t fifo_lock; + struct work_struct put_work; + + struct rm_cons_data *cons_data; +}; + +struct rm_cons_data { + struct tty_driver *tty_driver; + struct device *dev; + + spinlock_t ports_lock; + struct rm_cons_port *ports[RSC_MGR_TTY_ADAPTERS]; + + struct notifier_block rsc_mgr_notif; + struct console console; +}; + +static void put_work_fn(struct work_struct *ws) +{ + char buf[RM_CONS_WRITE_MSG_SIZE]; + int count, ret; + struct rm_cons_port *port =3D container_of(ws, struct rm_cons_port, put_w= ork); + + while (!kfifo_is_empty(&port->put_fifo)) { + count =3D kfifo_out_spinlocked(&port->put_fifo, buf, sizeof(buf), &port-= >fifo_lock); + if (count <=3D 0) + continue; + + ret =3D gh_rm_console_write(port->vmid, buf, count); + if (ret) { + pr_warn_once("failed to send characters: %d\n", ret); + break; + } + } +} + +static int rsc_mgr_console_notif(struct notifier_block *nb, unsigned long = cmd, void *data) +{ + int count, i; + struct rm_cons_port *rm_port =3D NULL; + struct tty_port *tty_port =3D NULL; + struct rm_cons_data *cons_data =3D container_of(nb, struct rm_cons_data, = rsc_mgr_notif); + const struct gh_rm_notification *notif =3D data; + struct gh_rm_notif_vm_console_chars const * const msg =3D notif->buff; + + if (cmd !=3D GH_RM_NOTIF_VM_CONSOLE_CHARS || + notif->size < sizeof(*msg)) + return NOTIFY_DONE; + + spin_lock(&cons_data->ports_lock); + for (i =3D 0; i < RSC_MGR_TTY_ADAPTERS; i++) { + if (!cons_data->ports[i]) + continue; + if (cons_data->ports[i]->vmid =3D=3D msg->vmid) { + rm_port =3D cons_data->ports[i]; + break; + } + } + if (rm_port) + tty_port =3D tty_port_get(&rm_port->port); + spin_unlock(&cons_data->ports_lock); + + if (!rm_port) + pr_warn("Received unexpected console characters for VMID %u\n", msg->vmi= d); + if (!tty_port) + return NOTIFY_DONE; + + count =3D tty_buffer_request_room(tty_port, msg->num_bytes); + tty_insert_flip_string(tty_port, msg->bytes, count); + tty_flip_buffer_push(tty_port); + + tty_port_put(tty_port); + return NOTIFY_OK; +} + +static ssize_t vmid_show(struct device *dev, struct device_attribute *attr= , char *buf) +{ + struct rm_cons_port *rm_port =3D dev_get_drvdata(dev); + + if (rm_port->vmid =3D=3D GH_VMID_SELF) + return sysfs_emit(buf, "self\n"); + + return sysfs_emit(buf, "%u\n", rm_port->vmid); +} + +static DEVICE_ATTR_RO(vmid); + +static struct attribute *rsc_mgr_tty_dev_attrs[] =3D { + &dev_attr_vmid.attr, + NULL +}; + +static const struct attribute_group rsc_mgr_tty_dev_attr_group =3D { + .attrs =3D rsc_mgr_tty_dev_attrs, +}; + +static const struct attribute_group *rsc_mgr_tty_dev_attr_groups[] =3D { + &rsc_mgr_tty_dev_attr_group, + NULL +}; + +static int rsc_mgr_tty_open(struct tty_struct *tty, struct file *filp) +{ + int ret; + struct rm_cons_port *rm_port =3D dev_get_drvdata(tty->dev); + + if (!rm_port->open) { + ret =3D gh_rm_console_open(rm_port->vmid); + if (ret) { + pr_err("Failed to open RM console for vmid %x: %d\n", rm_port->vmid, re= t); + return ret; + } + rm_port->open =3D true; + } + + return tty_port_open(&rm_port->port, tty, filp); +} + +static void rsc_mgr_tty_close(struct tty_struct *tty, struct file *filp) +{ + int ret; + struct rm_cons_port *rm_port =3D dev_get_drvdata(tty->dev); + + if (rm_port->open) { + if (rm_port->vmid !=3D GH_VMID_SELF) { + ret =3D gh_rm_console_close(rm_port->vmid); + if (ret) + pr_warn("Failed to close RM console for vmid %d: %d\n", + rm_port->vmid, ret); + } + rm_port->open =3D false; + + tty_port_close(&rm_port->port, tty, filp); + } + +} + +static int rsc_mgr_tty_write(struct tty_struct *tty, const unsigned char *= buf, int count) +{ + struct rm_cons_port *rm_port =3D dev_get_drvdata(tty->dev); + int ret; + + ret =3D kfifo_in_spinlocked(&rm_port->put_fifo, buf, count, &rm_port->fif= o_lock); + if (ret > 0) + schedule_work(&rm_port->put_work); + + return ret; +} + +static unsigned int rsc_mgr_mgr_tty_write_room(struct tty_struct *tty) +{ + struct rm_cons_port *rm_port =3D dev_get_drvdata(tty->dev); + + return kfifo_avail(&rm_port->put_fifo); +} + +static void rsc_mgr_console_write(struct console *co, const char *buf, uns= igned count) +{ + struct rm_cons_port *rm_port =3D co->data; + int ret; + + ret =3D kfifo_in_spinlocked(&rm_port->put_fifo, buf, count, &rm_port->fif= o_lock); + if (ret > 0) + schedule_work(&rm_port->put_work); +} + +static struct tty_driver *rsc_mgr_console_device(struct console *co, int *= index) +{ + struct rm_cons_port *rm_port =3D co->data; + + *index =3D rm_port->index; + return rm_port->port.tty->driver; +} + +static int rsc_mgr_console_setup(struct console *co, char *unused) +{ + int ret; + struct rm_cons_port *rm_port =3D co->data; + + if (!rm_port->open) { + ret =3D gh_rm_console_open(rm_port->vmid); + if (ret) { + pr_err("Failed to open RM console for vmid %x: %d\n", rm_port->vmid, re= t); + return ret; + } + rm_port->open =3D true; + } + + return 0; +} + +static int rsc_mgr_console_exit(struct console *co) +{ + int ret; + struct rm_cons_port *rm_port =3D co->data; + + if (rm_port->open) { + ret =3D gh_rm_console_close(rm_port->vmid); + if (ret) { + pr_err("Failed to close RM console for vmid %x: %d\n", rm_port->vmid, r= et); + return ret; + } + rm_port->open =3D false; + } + + return 0; +} + +static const struct tty_operations rsc_mgr_tty_ops =3D { + .open =3D rsc_mgr_tty_open, + .close =3D rsc_mgr_tty_close, + .write =3D rsc_mgr_tty_write, + .write_room =3D rsc_mgr_mgr_tty_write_room, +}; + +static void rsc_mgr_port_destruct(struct tty_port *port) +{ + struct rm_cons_port *rm_port =3D container_of(port, struct rm_cons_port, = port); + struct rm_cons_data *cons_data =3D rm_port->cons_data; + + spin_lock(&cons_data->ports_lock); + WARN_ON(cons_data->ports[rm_port->index] !=3D rm_port); + cons_data->ports[rm_port->index] =3D NULL; + spin_unlock(&cons_data->ports_lock); + kfree(rm_port); +} + +static const struct tty_port_operations rsc_mgr_port_ops =3D { + .destruct =3D rsc_mgr_port_destruct, +}; + +static struct rm_cons_port *rsc_mgr_port_create(struct rm_cons_data *cons_= data, u16 vmid) +{ + struct rm_cons_port *rm_port; + struct device *ttydev; + unsigned int index; + int ret; + + rm_port =3D kzalloc(sizeof(*rm_port), GFP_KERNEL); + rm_port->vmid =3D vmid; + INIT_KFIFO(rm_port->put_fifo); + spin_lock_init(&rm_port->fifo_lock); + INIT_WORK(&rm_port->put_work, put_work_fn); + tty_port_init(&rm_port->port); + rm_port->port.ops =3D &rsc_mgr_port_ops; + + spin_lock(&cons_data->ports_lock); + for (index =3D 0; index < RSC_MGR_TTY_ADAPTERS; index++) { + if (!cons_data->ports[index]) { + cons_data->ports[index] =3D rm_port; + rm_port->index =3D index; + break; + } + } + spin_unlock(&cons_data->ports_lock); + if (index >=3D RSC_MGR_TTY_ADAPTERS) { + ret =3D -ENOSPC; + goto err_put_port; + } + + ttydev =3D tty_port_register_device_attr(&rm_port->port, cons_data->tty_d= river, index, + cons_data->dev, rm_port, rsc_mgr_tty_dev_attr_groups); + if (IS_ERR(ttydev)) { + ret =3D PTR_ERR(ttydev); + goto err_put_port; + } + + return rm_port; +err_put_port: + tty_port_put(&rm_port->port); + return ERR_PTR(ret); +} + +static int rsc_mgr_console_probe(struct auxiliary_device *auxdev, + const struct auxiliary_device_id *aux_dev_id) +{ + struct rm_cons_data *cons_data; + struct rm_cons_port *rm_port; + int ret; + u16 vmid; + + cons_data =3D devm_kzalloc(&auxdev->dev, sizeof(*cons_data), GFP_KERNEL); + if (!cons_data) + return -ENOMEM; + dev_set_drvdata(&auxdev->dev, cons_data); + cons_data->dev =3D &auxdev->dev; + + cons_data->tty_driver =3D tty_alloc_driver(RSC_MGR_TTY_ADAPTERS, + TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(cons_data->tty_driver)) + return PTR_ERR(cons_data->tty_driver); + + cons_data->tty_driver->driver_name =3D "gh"; + cons_data->tty_driver->name =3D "ttyGH"; + cons_data->tty_driver->type =3D TTY_DRIVER_TYPE_SYSTEM; + cons_data->tty_driver->init_termios =3D tty_std_termios; + tty_set_operations(cons_data->tty_driver, &rsc_mgr_tty_ops); + + ret =3D tty_register_driver(cons_data->tty_driver); + if (ret) { + dev_err(&auxdev->dev, "Could not register tty driver: %d\n", ret); + goto err_put_tty; + } + + spin_lock_init(&cons_data->ports_lock); + + cons_data->rsc_mgr_notif.notifier_call =3D rsc_mgr_console_notif; + ret =3D gh_rm_register_notifier(&cons_data->rsc_mgr_notif); + if (ret) { + dev_err(&auxdev->dev, "Could not register for resource manager notificat= ions: %d\n", + ret); + goto err_put_tty; + } + + rm_port =3D rsc_mgr_port_create(cons_data, GH_VMID_SELF); + if (IS_ERR(rm_port)) { + ret =3D PTR_ERR(rm_port); + dev_err(&auxdev->dev, "Could not create own console: %d\n", ret); + goto err_unreg_notif; + } + + strncpy(cons_data->console.name, "ttyGH", sizeof(cons_data->console.name)= ); + cons_data->console.write =3D rsc_mgr_console_write; + cons_data->console.device =3D rsc_mgr_console_device; + cons_data->console.setup =3D rsc_mgr_console_setup; + cons_data->console.exit =3D rsc_mgr_console_exit; + cons_data->console.index =3D rm_port->index; + cons_data->console.data =3D rm_port; + register_console(&cons_data->console); + + ret =3D gh_rm_get_vmid(&vmid); + if (!ret) { + rm_port =3D rsc_mgr_port_create(cons_data, vmid); + if (IS_ERR(rm_port)) + dev_warn(&auxdev->dev, "Could not create loop-back console: %ld\n", + PTR_ERR(rm_port)); + } else { + dev_warn(&auxdev->dev, "Failed to get this VM's VMID: %d. Not creating l= oop-back console\n", + ret); + } + + return 0; +err_unreg_notif: + gh_rm_unregister_notifier(&cons_data->rsc_mgr_notif); +err_put_tty: + tty_driver_kref_put(cons_data->tty_driver); + return ret; +} + +static void rsc_mgr_console_remove(struct auxiliary_device *auxdev) +{ + struct rm_cons_data *cons_data =3D dev_get_drvdata(&auxdev->dev); + + unregister_console(&cons_data->console); + gh_rm_unregister_notifier(&cons_data->rsc_mgr_notif); + tty_driver_kref_put(cons_data->tty_driver); +} + +static struct auxiliary_device_id rsc_mgr_console_ids[] =3D { + { .name =3D "gunyah_rsc_mgr.console" }, + {} +}; +MODULE_DEVICE_TABLE(auxiliary, rsc_mgr_console_ids); + +static struct auxiliary_driver rsc_mgr_console_drv =3D { + .probe =3D rsc_mgr_console_probe, + .remove =3D rsc_mgr_console_remove, + .id_table =3D rsc_mgr_console_ids, +}; +module_auxiliary_driver(rsc_mgr_console_drv); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Console"); --=20 2.25.1