From patchwork Thu Feb 22 23:16:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 775238 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB65A146E64; Thu, 22 Feb 2024 23:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708643836; cv=none; b=NYjoC3zS1i63TGwXvFOODg5NWnKh7TKv1QX7TRww5FIVfHCcUSbNn63HE4/TagWTc/15EkXc4T0NMtJpN+8kgeNBIJtVYj/yYVmcdIKngpkYjGjr6+Md63g2Nqp8cDGg9YEonZDgLcIHV0EfUY+nzF001xNRViS7ZDjjq9NEjAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708643836; c=relaxed/simple; bh=g6Ul15lT4i7ZnuRAKyLa5seTTA8HkCymkbeHVuvzl2g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=c+FLjptkQk8btO+prggvSBYDpscn7K6+jX/lforQIKpU8uNve+JlG4j3bOE9jj7hN/kJyEVPHAWzlqQPZeIjdmh/Bo4KoDrnZUqJy+W0+lrptSgVNPzzk7hbPMSEs/ddTHz6DqczI5+xvYEfuZXhIKYj0NgH3QVoWSIbkf8T7YM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=HWAtZntv; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="HWAtZntv" Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MNEFgc001638; Thu, 22 Feb 2024 23:16:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=BuEOFyDcoeCThxuQAKrvGhwyWtW7DRLhCyudyTBCcFA =; b=HWAtZntvqxz5chWhMypDUNBSYkg+/4PVsA98haVnAi08rpWmpYTf4gG1xfY /8NWoCQ3wzAM5kwljBOxDz0OdTrd+9wcxSMeZt3/ikvG7DRpz3x0LyW3cnjdgNQZ +TqTOg6OQPyG1wmtZO62Z5zsAb6APu1bCwVKNmfT7aVDR4Ya40DdtCznOt33lX8Y PV7xE8qpQBSrUpmhc2nudC2cIV/WYVpGjcQyEP7lRHMinp7MLjL/hlYSoyPh5bx3 ILoUXsdCzgJEjvTqZ3AiKxl0tJQKJYWUrS37C7wpBejvCBg/WMwKDS2iM9oguR7K +oB9CLqCOuZyAtzIqDqcKNi0vQw== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wdvwwbj73-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:43 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGgfU018270 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:42 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:42 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:50 -0800 Subject: [PATCH v17 27/35] gunyah: rsc_mgr: Add RPC to enable demand paging Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-27-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: S8HPNkxOEDjWpTzRV8lNGcyD-Qx9mQEa X-Proofpoint-GUID: S8HPNkxOEDjWpTzRV8lNGcyD-Qx9mQEa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 spamscore=0 impostorscore=0 mlxlogscore=785 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 Add Gunyah Resource Manager RPC to enable demand paging for a virtual machine. Resource manager needs to be informed of private memory regions which will be demand paged and the location where the DTB memory parcel should live in the guest's address space. Signed-off-by: Elliot Berman --- drivers/virt/gunyah/rsc_mgr.h | 12 +++++++ drivers/virt/gunyah/rsc_mgr_rpc.c | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index 68d08d3cff02d..99c2db18579ca 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -108,6 +108,18 @@ int gunyah_rm_get_hyp_resources(struct gunyah_rm *rm, u16 vmid, int gunyah_rm_get_vmid(struct gunyah_rm *rm, u16 *vmid); +int gunyah_rm_vm_set_demand_paging(struct gunyah_rm *rm, u16 vmid, u32 count, + struct gunyah_rm_mem_entry *mem_entries); + +enum gunyah_rm_range_id { + GUNYAH_RM_RANGE_ID_IMAGE = 0, + GUNYAH_RM_RANGE_ID_FIRMWARE = 1, +}; + +int gunyah_rm_vm_set_address_layout(struct gunyah_rm *rm, u16 vmid, + enum gunyah_rm_range_id range_id, + u64 base_address, u64 size); + struct gunyah_resource * gunyah_rm_alloc_resource(struct gunyah_rm *rm, struct gunyah_rm_hyp_resource *hyp_resource); diff --git a/drivers/virt/gunyah/rsc_mgr_rpc.c b/drivers/virt/gunyah/rsc_mgr_rpc.c index 99e5a3f1a5bb9..dfffcf02ddaea 100644 --- a/drivers/virt/gunyah/rsc_mgr_rpc.c +++ b/drivers/virt/gunyah/rsc_mgr_rpc.c @@ -24,6 +24,8 @@ #define GUNYAH_RM_RPC_VM_INIT 0x5600000B #define GUNYAH_RM_RPC_VM_GET_HYP_RESOURCES 0x56000020 #define GUNYAH_RM_RPC_VM_GET_VMID 0x56000024 +#define GUNYAH_RM_RPC_VM_SET_DEMAND_PAGING 0x56000033 +#define GUNYAH_RM_RPC_VM_SET_ADDRESS_LAYOUT 0x56000034 /* clang-format on */ struct gunyah_rm_vm_common_vmid_req { @@ -103,6 +105,23 @@ struct gunyah_rm_vm_config_image_req { __le64 dtb_size; } __packed; +/* Call: VM_SET_DEMAND_PAGING */ +struct gunyah_rm_vm_set_demand_paging_req { + __le16 vmid; + __le16 _padding; + __le32 range_count; + DECLARE_FLEX_ARRAY(struct gunyah_rm_mem_entry, ranges); +} __packed; + +/* Call: VM_SET_ADDRESS_LAYOUT */ +struct gunyah_rm_vm_set_address_layout_req { + __le16 vmid; + __le16 _padding; + __le32 range_id; + __le64 range_base; + __le64 range_size; +} __packed; + /* * Several RM calls take only a VMID as a parameter and give only standard * response back. Deduplicate boilerplate code by using this common call. @@ -494,3 +513,57 @@ int gunyah_rm_get_vmid(struct gunyah_rm *rm, u16 *vmid) return ret; } EXPORT_SYMBOL_GPL(gunyah_rm_get_vmid); + +/** + * gunyah_rm_vm_set_demand_paging() - Enable demand paging of memory regions + * @rm: Handle to a Gunyah resource manager + * @vmid: VMID of the other VM + * @count: Number of demand paged memory regions + * @entries: Array of the regions + */ +int gunyah_rm_vm_set_demand_paging(struct gunyah_rm *rm, u16 vmid, u32 count, + struct gunyah_rm_mem_entry *entries) +{ + struct gunyah_rm_vm_set_demand_paging_req *req __free(kfree) = NULL; + size_t req_size; + + req_size = struct_size(req, ranges, count); + if (req_size == SIZE_MAX) + return -EINVAL; + + req = kzalloc(req_size, GFP_KERNEL); + if (!req) + return -ENOMEM; + + req->vmid = cpu_to_le16(vmid); + req->range_count = cpu_to_le32(count); + memcpy(req->ranges, entries, sizeof(*entries) * count); + + return gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_SET_DEMAND_PAGING, req, + req_size, NULL, NULL); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_set_demand_paging, ERRNO); + +/** + * gunyah_rm_vm_set_address_layout() - Set the start address of images + * @rm: Handle to a Gunyah resource manager + * @vmid: VMID of the other VM + * @range_id: Which image to set + * @base_address: Base address + * @size: Size + */ +int gunyah_rm_vm_set_address_layout(struct gunyah_rm *rm, u16 vmid, + enum gunyah_rm_range_id range_id, + u64 base_address, u64 size) +{ + struct gunyah_rm_vm_set_address_layout_req req = { + .vmid = cpu_to_le16(vmid), + .range_id = cpu_to_le32(range_id), + .range_base = cpu_to_le64(base_address), + .range_size = cpu_to_le64(size), + }; + + return gunyah_rm_call(rm, GUNYAH_RM_RPC_VM_SET_ADDRESS_LAYOUT, &req, + sizeof(req), NULL, NULL); +} +ALLOW_ERROR_INJECTION(gunyah_rm_vm_set_address_layout, ERRNO);