From patchwork Thu Feb 22 23:16:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 747EBC54E4A for ; Thu, 22 Feb 2024 23:17:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 739676B00A5; Thu, 22 Feb 2024 18:16:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BE876B00A7; Thu, 22 Feb 2024 18:16:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D58896B00A5; Thu, 22 Feb 2024 18:16:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 95F0C6B00A4 for ; Thu, 22 Feb 2024 18:16:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 63AB5A177F for ; Thu, 22 Feb 2024 23:16:53 +0000 (UTC) X-FDA: 81821001906.06.1AF91F0 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf19.hostedemail.com (Postfix) with ESMTP id 24CFF1A001B for ; Thu, 22 Feb 2024 23:16:50 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=ESuisxBc; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf19.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643811; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w8rE8S1Pv8IOr8KcghO6tPSQw40M/mDtX+e2e/iQtlM=; b=Osas7tDazmqxgR+ay/yBk4xn6jlwEC4IMItpgxrK+joMdycjc0peIi4Ic4eN6Y2LFuEFwA Wf5Rc9ZQBQRI3Yd0sU2u9mqlsCi1AjIjeSqPVJ1Qvlg6BByKfiQi3C8+A3LWty4Gdfy1BS Z+wfyapezUchUBuOI8MaEM2GBCqXqHs= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=ESuisxBc; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf19.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643811; a=rsa-sha256; cv=none; b=uC7XIh5fYHB6pKD0ylYOLPjdyt0mY8rHGkaB9fFCb6CPq8NnffW9MrqMiAVsjIqinZNDay xuLmC6eF5gVbut3S6kNjKsOiGUvvMAt3OlsVKjJyOON5c2i2TxL48xVgrW73cwGQx4+1xN z0/hiQeVd13ArbUJYbFDfGHNBBdlfVs= Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MM2ID0024414; Thu, 22 Feb 2024 23:16:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=w8rE8S1Pv8IOr8KcghO6tPSQw40M/mDtX+e2e/iQtlM =; b=ESuisxBcPaertvoLFuq93cv0T2QQJrTLj+eldogd3CjopQSs/3778M+gUzS jxj/9CKVTRjdSf6ag9jlFmwJtIF1SQmYE4b9HJyhDGaJ1uExLqIiyhZUMputt8/a wRF7XRlx5bM67l1IsKELORQM9CEU1a3JEldxo8raeT4RWsxEVYFi1Vr94pLebWbd jgRNAU0g4P/nIxpcGJuRfLhssO+P7muGdsxejQ6O/XGVlp1gWfJh/lr48DGSJ8e7 eCjN7nckeH9WmcPhh+zhekA0m90zCVqHCqosS/o8VbBvx7YOaVKaZvXD/PJmDf6D stCWfDyTc+mRoSthKgWXAgMYLMw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we1b0jxsy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:42 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGgO2016070 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:42 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 22 Feb 2024 15:16:41 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:49 -0800 Subject: [PATCH v17 26/35] virt: gunyah: Share guest VM dtb configuration to Gunyah MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-26-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: sZnW-kKef_N-x5v7jSsFunG273vEf6tT X-Proofpoint-GUID: sZnW-kKef_N-x5v7jSsFunG273vEf6tT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 24CFF1A001B X-Stat-Signature: ix1c8z5z515moao46upamxdbabf8rnbo X-Rspam-User: X-HE-Tag: 1708643810-296949 X-HE-Meta: U2FsdGVkX18+v1zBudo20FAdsYp9VFnEw7L0r773lFOvwxYL4xvP7qoqSVyzfF1bii19n3trAoali6FpKlvtQEdnvfJKsu3fkUKCy+4YsLlBVJg6zvMuZbiPUHg6FVvxlc/gLdOE1OK5k8PIlvNft4FLdukuRbs12u+35N1dLjdI9xyxcBdTpEg2rpBqve1tfhBTia1/SsK0/FZD8V8clZa4yhPcE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SDhOxDrJefg/NA6UG3eYR7k6BiB8ErvJ+pR8DC/TZjnhBbvGYvybEZ+8e2ie3MgpdEyRbsX5YByTol+FE1hZ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Gunyah Resource Manager sets up a virtual machine based on a device tree which lives in guest memory. Resource manager requires this memory to be provided as a memory parcel for it to read and manipulate. Construct a memory parcel, lend it to the virtual machine, and inform resource manager about the device tree location (the memory parcel ID and offset into the memory parcel). Signed-off-by: Elliot Berman --- drivers/virt/gunyah/vm_mgr.c | 45 ++++++++++++++++++++++++++++++++++++++++++-- drivers/virt/gunyah/vm_mgr.h | 13 ++++++++++++- include/uapi/linux/gunyah.h | 14 ++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c index 43878a39d4714..198a99d78c44c 100644 --- a/drivers/virt/gunyah/vm_mgr.c +++ b/drivers/virt/gunyah/vm_mgr.c @@ -452,8 +452,23 @@ static int gunyah_vm_start(struct gunyah_vm *ghvm) ghvm->vmid = ret; ghvm->vm_status = GUNYAH_RM_VM_STATUS_LOAD; - ret = gunyah_rm_vm_configure(ghvm->rm, ghvm->vmid, ghvm->auth, 0, 0, 0, - 0, 0); + ghvm->dtb.parcel_start = ghvm->dtb.config.guest_phys_addr >> PAGE_SHIFT; + ghvm->dtb.parcel_pages = ghvm->dtb.config.size >> PAGE_SHIFT; + ret = gunyah_gmem_share_parcel(ghvm, &ghvm->dtb.parcel, + &ghvm->dtb.parcel_start, + &ghvm->dtb.parcel_pages); + if (ret) { + dev_warn(ghvm->parent, + "Failed to allocate parcel for DTB: %d\n", ret); + goto err; + } + + ret = gunyah_rm_vm_configure(ghvm->rm, ghvm->vmid, ghvm->auth, + ghvm->dtb.parcel.mem_handle, 0, 0, + ghvm->dtb.config.guest_phys_addr - + (ghvm->dtb.parcel_start + << PAGE_SHIFT), + ghvm->dtb.config.size); if (ret) { dev_warn(ghvm->parent, "Failed to configure VM: %d\n", ret); goto err; @@ -536,6 +551,21 @@ static long gunyah_vm_ioctl(struct file *filp, unsigned int cmd, long r; switch (cmd) { + case GUNYAH_VM_SET_DTB_CONFIG: { + struct gunyah_vm_dtb_config dtb_config; + + if (copy_from_user(&dtb_config, argp, sizeof(dtb_config))) + return -EFAULT; + + if (overflows_type(dtb_config.guest_phys_addr + dtb_config.size, + u64)) + return -EOVERFLOW; + + ghvm->dtb.config = dtb_config; + + r = 0; + break; + } case GUNYAH_VM_START: { r = gunyah_vm_ensure_started(ghvm); break; @@ -594,6 +624,17 @@ static void _gunyah_vm_put(struct kref *kref) if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_RUNNING) gunyah_vm_stop(ghvm); + if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_LOAD || + ghvm->vm_status == GUNYAH_RM_VM_STATUS_READY || + ghvm->vm_status == GUNYAH_RM_VM_STATUS_INIT_FAILED) { + ret = gunyah_gmem_reclaim_parcel(ghvm, &ghvm->dtb.parcel, + ghvm->dtb.parcel_start, + ghvm->dtb.parcel_pages); + if (ret) + dev_err(ghvm->parent, + "Failed to reclaim DTB parcel: %d\n", ret); + } + gunyah_vm_remove_functions(ghvm); down_write(&ghvm->bindings_lock); diff --git a/drivers/virt/gunyah/vm_mgr.h b/drivers/virt/gunyah/vm_mgr.h index b6bc66f018b09..d8c299e5cf7cc 100644 --- a/drivers/virt/gunyah/vm_mgr.h +++ b/drivers/virt/gunyah/vm_mgr.h @@ -74,6 +74,13 @@ long gunyah_dev_vm_mgr_ioctl(struct gunyah_rm *rm, unsigned int cmd, * @resource_tickets: List of &struct gunyah_vm_resource_ticket * @auth: Authentication mechanism to be used by resource manager when * launching the VM + * @dtb: For tracking dtb configuration when launching the VM + * @dtb.config: Location of the DTB in the guest memory + * @dtb.parcel_start: Guest frame number where the memory parcel that we lent to + * VM (DTB could start in middle of folio; we lend entire + * folio; parcel_start is start of the folio) + * @dtb.parcel_pages: Number of pages lent for the memory parcel + * @dtb.parcel: Data for resource manager to lend the parcel * * Members are grouped by hot path. */ @@ -103,7 +110,11 @@ struct gunyah_vm { struct device *parent; enum gunyah_rm_vm_auth_mechanism auth; - + struct { + struct gunyah_vm_dtb_config config; + u64 parcel_start, parcel_pages; + struct gunyah_rm_mem_parcel parcel; + } dtb; }; /** diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h index 1af4c5ae6bc3e..a89d9bedf3e5d 100644 --- a/include/uapi/linux/gunyah.h +++ b/include/uapi/linux/gunyah.h @@ -42,6 +42,20 @@ struct gunyah_create_mem_args { /* * ioctls for gunyah-vm fds (returned by GUNYAH_CREATE_VM) */ + +/** + * struct gunyah_vm_dtb_config - Set the location of the VM's devicetree blob + * @guest_phys_addr: Address of the VM's devicetree in guest memory. + * @size: Maximum size of the devicetree including space for overlays. + * Resource manager applies an overlay to the DTB and dtb_size should + * include room for the overlay. A page of memory is typicaly plenty. + */ +struct gunyah_vm_dtb_config { + __u64 guest_phys_addr; + __u64 size; +}; +#define GUNYAH_VM_SET_DTB_CONFIG _IOW(GUNYAH_IOCTL_TYPE, 0x2, struct gunyah_vm_dtb_config) + #define GUNYAH_VM_START _IO(GUNYAH_IOCTL_TYPE, 0x3) /**