From patchwork Wed Oct 26 18:58:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13021029 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 E50C8C38A2D for ; Wed, 26 Oct 2022 19:01:45 +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=wxPcxZYO0OZg3FQWO4R529upuno/Vva8ookOrCmEN2k=; b=ITTuoiJ+L5sucT YBBaqaonwncBIAHX/nTcYBfryEG6sY5A0nmcjXU+GNwkqxV+w8smaDFr0RWaBinoiSFdLdyn6e/Zn JSaNehhUrrh2n1/5RnBl3f7k05yr38OUttrOzdHeGbh/AQofUU360zq2CU/DuH+Z1ypgqZx1ECgbx cD6+RwJuGaM4JhErgmXjjOv93DEqWRDvRYRtFDEJUA3qaJ2eYnfvAuKXuM+WUhc2HyhVSYQuSb2rk HCjV6vUIfoH4/YW52P/1SjdQCXCT9zuOdOi8AHq1ywgorN7xm3U0IQ7u+0/lF2ugv0jmk+FFYqcN1 +YMkfqV99JZlQcIOqRoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onldj-00AdPh-II; Wed, 26 Oct 2022 19:00:35 +0000 Received: from alexa-out-sd-01.qualcomm.com ([199.106.114.38]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1onlcp-00Ad1D-2X for linux-arm-kernel@lists.infradead.org; Wed, 26 Oct 2022 18:59:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1666810779; x=1698346779; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s5typUUdhXFp1GKE5UGm4GuEmmY0sum1RlFlPPqo1JA=; b=G02k/YxDdqLS2w8W7Jf0MZaSoag+xci2C07bpVqaiULbV3FujVcE92x1 Na/WPBk/GCL/nryza3LRZdhLr9PDAfmv2TpxL1rMd3dtD+WqVre05/5Ge DdQ3apZ89KK0+jIW4G40jBcXhgTPkgAvw7wyn2td1KmARFvjEomnx+ejK g=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-01.qualcomm.com with ESMTP; 26 Oct 2022 11:59:39 -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; 26 Oct 2022 11:59:38 -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, 26 Oct 2022 11:59:37 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Prakruthi Deepak Heragu , 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 , Srinivas Kandagatla , Amol Maheshwari , Kalle Valo , , , , Subject: [PATCH v6 18/21] gunyah: rsc_mgr: Add platform ops on mem_lend/mem_reclaim Date: Wed, 26 Oct 2022 11:58:43 -0700 Message-ID: <20221026185846.3983888-19-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221026185846.3983888-1-quic_eberman@quicinc.com> References: <20221026185846.3983888-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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-20221026_115939_185250_9ED209A0 X-CRM114-Status: GOOD ( 20.96 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Qualcomm platforms, there is a firmware entity which controls access to physical pages. In order to share memory with another VM, this entity needs to be informed that the guest VM should have access to the memory. Co-developed-by: Prakruthi Deepak Heragu Signed-off-by: Prakruthi Deepak Heragu Signed-off-by: Elliot Berman --- drivers/virt/gunyah/rsc_mgr.c | 52 +++++++++++++++++++++++++++++++ drivers/virt/gunyah/rsc_mgr.h | 3 ++ drivers/virt/gunyah/rsc_mgr_rpc.c | 7 +++++ include/linux/gunyah_rsc_mgr.h | 12 ++++++- 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/virt/gunyah/rsc_mgr.c b/drivers/virt/gunyah/rsc_mgr.c index f2f776edecb8..6e590f2a8cfa 100644 --- a/drivers/virt/gunyah/rsc_mgr.c +++ b/drivers/virt/gunyah/rsc_mgr.c @@ -105,6 +105,13 @@ struct gh_rsc_mgr { static struct gh_rsc_mgr *__rsc_mgr; SRCU_NOTIFIER_HEAD_STATIC(gh_rm_notifier); +/* Needs to be out of the gh_rsc_mgr struct as platform_ops might probe before + * rsc mgr probes. We can't defer the platform_ops because it might be that + * Linux is not a Gunyah guest. + */ +static struct gunyah_rm_platform_ops *rm_platform_ops; +static DECLARE_RWSEM(rm_platform_ops_lock); + static struct gh_rm_connection *gh_rm_alloc_connection(u32 msg_id, u8 type) { struct gh_rm_connection *connection; @@ -498,6 +505,51 @@ int gh_rm_call(u32 message_id, void *req_buff, size_t req_buff_size, return ret; } +int gh_rm_platform_pre_mem_share(struct gh_rm_mem_parcel *mem_parcel) +{ + int ret = 0; + + down_read(&rm_platform_ops_lock); + if (rm_platform_ops && rm_platform_ops->pre_mem_share) + ret = rm_platform_ops->pre_mem_share(mem_parcel); + up_read(&rm_platform_ops_lock); + return ret; +} + +int gh_rm_platform_post_mem_reclaim(struct gh_rm_mem_parcel *mem_parcel) +{ + int ret = 0; + + down_read(&rm_platform_ops_lock); + if (rm_platform_ops && rm_platform_ops->post_mem_reclaim) + ret = rm_platform_ops->post_mem_reclaim(mem_parcel); + up_read(&rm_platform_ops_lock); + return ret; +} + +int gh_rm_register_platform_ops(struct gunyah_rm_platform_ops *platform_ops) +{ + int ret = 0; + + down_write(&rm_platform_ops_lock); + if (!rm_platform_ops) + rm_platform_ops = platform_ops; + else + ret = -EEXIST; + up_write(&rm_platform_ops_lock); + return ret; +} +EXPORT_SYMBOL_GPL(gh_rm_register_platform_ops); + +void gh_rm_unregister_platform_ops(struct gunyah_rm_platform_ops *platform_ops) +{ + down_write(&rm_platform_ops_lock); + if (rm_platform_ops == platform_ops) + rm_platform_ops = NULL; + up_write(&rm_platform_ops_lock); +} +EXPORT_SYMBOL_GPL(gh_rm_unregister_platform_ops); + int gh_rm_register_notifier(struct notifier_block *nb) { return srcu_notifier_chain_register(&gh_rm_notifier, nb); diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index f6ed58405ef4..49becf82edf7 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -130,6 +130,9 @@ struct gh_vm_set_boot_context_req { int gh_rm_call(u32 message_id, void *req_buff, size_t req_buff_size, void **resp_buf, size_t *resp_buff_size); +int gh_rm_platform_pre_mem_share(struct gh_rm_mem_parcel *mem_parcel); +int gh_rm_platform_post_mem_reclaim(struct gh_rm_mem_parcel *mem_parcel); + struct gh_rm_device { struct device dev; const char *name; diff --git a/drivers/virt/gunyah/rsc_mgr_rpc.c b/drivers/virt/gunyah/rsc_mgr_rpc.c index 17f88c3d5726..c7e3bb975640 100644 --- a/drivers/virt/gunyah/rsc_mgr_rpc.c +++ b/drivers/virt/gunyah/rsc_mgr_rpc.c @@ -120,6 +120,10 @@ static int gh_rm_mem_lend_common(u32 message_id, struct gh_rm_mem_parcel *p) if (initial_n_mem_entries > GH_RM_MAX_MEM_ENTRIES) initial_n_mem_entries = GH_RM_MAX_MEM_ENTRIES; + ret = gh_rm_platform_pre_mem_share(p); + if (ret) + return ret; + /* The format of the message goes: * request header * ACL entries (which VMs get what kind of access to this memory parcel) @@ -163,6 +167,7 @@ static int gh_rm_mem_lend_common(u32 message_id, struct gh_rm_mem_parcel *p) if (resp_size != sizeof(u32)) { ret = -EIO; + gh_rm_platform_post_mem_reclaim(p); goto out; } @@ -234,6 +239,8 @@ int gh_rm_mem_reclaim(struct gh_rm_mem_parcel *parcel) if (resp_size) pr_warn("Received unexpected payload for MEM_RECLAIM: %lu\n", resp_size); + ret = gh_rm_platform_post_mem_reclaim(parcel); + return ret; } EXPORT_SYMBOL_GPL(gh_rm_mem_reclaim); diff --git a/include/linux/gunyah_rsc_mgr.h b/include/linux/gunyah_rsc_mgr.h index 78d516032f6a..6e5e67e96688 100644 --- a/include/linux/gunyah_rsc_mgr.h +++ b/include/linux/gunyah_rsc_mgr.h @@ -119,7 +119,6 @@ struct gh_rm_hyp_resource { } __packed; ssize_t gh_rm_get_hyp_resources(u16 vmid, struct gh_rm_hyp_resource **resources); -int gh_rm_get_vmid(u16 *vmid); #define GH_RM_BOOT_CONTEXT_REG_SET_REGISTERS 0 #define GH_RM_BOOT_CONTEXT_REG_SET_PC 1 @@ -143,4 +142,15 @@ void gh_rm_driver_unregister(struct gh_rm_driver *ghrm_drv); #define module_gh_rm_driver(ghrm_drv) \ module_driver(ghrm_drv, gh_rm_driver_register, gh_rm_driver_unregister) +#if IS_ENABLED(CONFIG_GUNYAH) +int gh_rm_register_platform_ops(struct gunyah_rm_platform_ops *platform_ops); +void gh_rm_unregister_platform_ops(struct gunyah_rm_platform_ops *platform_ops); +int gh_rm_get_vmid(u16 *vmid); +#else +static inline int gh_rm_register_platform_ops(struct gunyah_rm_platform_ops *platform_ops) + { return 0; } +static inline void gh_rm_unregister_platform_ops(struct gunyah_rm_platform_ops *platform_ops) { } +static inline int gh_rm_get_vmid(u16 *vmid) { return -ENODEV; } +#endif + #endif