From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C577C04A95 for ; Wed, 28 Sep 2022 20:00:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=v3SgyXCcGsAiBFfjGIx6S/0QR8Wfe8qn42ZOz507S0E=; b=BD4QQ9Q20QbdTb vGi5KDEUKr1gssUGYlTzpwnCIraWVHCeg7Ml0v52UnJZQ0wmdjOOBkmJnyTr2gv3lympEHgLDFLIW HSIfkL2STJqmzvlU0mVsdKtkSJ7teGSZzdgsIfWB0sSV2lJ7Yuu7MM92/nY8gyZN6XJURY3pJ1e/S PlR6HEK7rMN4sq13P3IQzfn7PEC1KdywudmbFJgJYL9S+7ic45Hf/3H/e8JuRadc4MYaLzOEbza0Z aulIdI87wO/Ko8Jmtz8QkrA5clroybQAP1MDy6Oajv0bciaQNdI6xNRFy6xXJDQkWURUQteeeDZGX UgVgxv1LsfG6wcxsgprg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oddD2-000CWl-92; Wed, 28 Sep 2022 19:59:09 +0000 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oddBV-000Bua-PC for linux-arm-kernel@lists.infradead.org; Wed, 28 Sep 2022 19:57:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1664395053; x=1695931053; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2IVpUNrnjO4ojAkyzvSTcWNFQsgnbraPAVbS8edeKUc=; b=nFOpQALnl8lyQiXH4isKtbEhPGvEDWjzAmx4Ow8TLwi3ZrSjYcWD8mCy qyGdJVzYSAIbQGPzMzMgI269VRv8acFmtf+FGmYziLOFuhjnbQCbCU88u 2PEHC9VyvqNt9UZQNmyqzTu2Inlc1VtcSeHVbXgEX4H9cLTl0fvcz+r0J 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220928_125733_872559_9F4F1216 X-CRM114-Status: GOOD ( 22.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 += sysfs.o obj-$(CONFIG_GUNYAH) += gunyah.o -gunyah_rsc_mgr-y += rsc_mgr.o +gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o obj-$(CONFIG_GUNYAH_RESORUCE_MANAGER) += 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 +/* 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); diff --git a/drivers/virt/gunyah/rsc_mgr_rpc.c b/drivers/virt/gunyah/rsc_mgr_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 = 0; + + ret = gh_rm_call(GH_RM_RPC_VM_GET_VMID, &payload, sizeof(payload), &resp, &resp_size); + if (ret) + return ret; + + if (resp_size != sizeof(*vmid)) + return -EIO; + *vmid = *(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_SELF, 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 = {0}; + size_t resp_size; + int ret; + + req_payload.vmid = vmid; + + ret = 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 = {0}; + size_t resp_size; + int ret; + + req_payload.vmid = vmid; + + ret = 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_size); + + 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 = 0; + size_t req_payload_size = sizeof(*req_payload) + size; + + if (size < 1 || size > (U32_MAX - sizeof(*req_payload))) + return -EINVAL; + + req_payload = kzalloc(req_payload_size, GFP_KERNEL); + + if (!req_payload) + return -ENOMEM; + + req_payload->vmid = vmid; + req_payload->num_bytes = size; + memcpy(req_payload->data, buf, size); + + ret = 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_size); + + 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 = {0}; + size_t resp_size; + int ret; + + req_payload.vmid = vmid; + + ret = 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_size); + + 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); +/* 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 -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel