Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp542970rdd; Tue, 9 Jan 2024 11:40:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0PDzKMAZcnPspX6PvrQ5gEDVEi4UscGOdjfcxbotYZhj7Od4a/ZVdg4pp1zbJ++rsNqLo X-Received: by 2002:a17:90b:2407:b0:28a:325d:1ed8 with SMTP id nr7-20020a17090b240700b0028a325d1ed8mr2665365pjb.26.1704829232707; Tue, 09 Jan 2024 11:40:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704829232; cv=none; d=google.com; s=arc-20160816; b=afYauAFReT1lzCPJL6m+iGlBL35t4G2ZQbNtvOL76J5fB2KrH7uBXVQY+S1RQ1DmvN GsjBap2DhtkXY6Ph425lRfC7XAg/BSj6BthJE3vOz79oOgXJW7kLGZX6HOvHW9XsJuug AsqcNQfTx809/iP+wGNM4pOtIMgpUPjRux2RNNUbgk0IbQu8GJMa1RvqKJP+rNozZ1Kg C4/UDKW14XMRujXLn5W6tX3k/E68ZiIKTQG9P8I5u62gBYTE/Mcqd5x+B/S8sQb60Z/P rDu5VJVvEY3XsULDSMrIEzc0BBPVAyO7skj0KQTrVG2hktDh7ZePRAwkRx+z6CIHcDJV E9tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=jqaSvaTcT+GljjucYsOF+tmQD3YLMOiGYv13cJ7TCoM=; fh=j53ffieBeHmuArQHAkiXDczYOIriM+Jf92hqYE3BW8U=; b=hI/VCwvIcCzO0Gz4vu3KMyxpy65tEd2xUktyZ2harAb25k3qLlPZCb3eIsYE9ZbOqh KtKyvtFYvH20j0rInXZo+vE4c9lzAmhXAHCxxleXITZnkCPShQupvSjrYZmrcbHzU9Mb Mteb6mnkj6ercuKKVD6RIx6SqGj4WO8SlY8ejc/CvjKDNOSJexv+nl+MVDp8+ZmIqRcB jgRe5qb5O51PwRkIpZzuK1VKGh9NzbohRkfZRjn8CUmOgdRR+HtLVgWCja/ixXE4gYld jYTJZzF3SvKjOO6v8xfCx9Jo2jrKzJsNj6j+hd4DZz73z7uwCeKxz2tC9aV5et14UB0Y 6vKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=mS13sR+J; spf=pass (google.com: domain of linux-kernel+bounces-21331-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21331-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id in7-20020a17090b438700b0028d1c469133si6840300pjb.71.2024.01.09.11.40.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 11:40:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21331-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=mS13sR+J; spf=pass (google.com: domain of linux-kernel+bounces-21331-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21331-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AE4FA288A72 for ; Tue, 9 Jan 2024 19:40:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A56313EA98; Tue, 9 Jan 2024 19:38:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="mS13sR+J" 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 057D03D3A0; Tue, 9 Jan 2024 19:38:17 +0000 (UTC) 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 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 409JU9kp019882; Tue, 9 Jan 2024 19:37:59 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=jqaSvaTcT+GljjucYsOF+tmQD3YLMOiGYv13cJ7TCoM =; b=mS13sR+JttsNvcp6XncL1NE4Z+aQTzx6gyas4nrjZDP95B/RvilY/8oaI0a IrEFyq+I6d0z8BKLwxl3DtNx3WVo2ZWPnsKnFYc0CP4DshreW7BEz6vQs3q3lxlg 6+IDUH+nEnX0cfstiddGgIw5G49XiWy2l8URmkJQmtT9q5Mylwbq2jp89fH3eMYM b2U14+nPwo4LyvTYRvFk9tvi3ipqBeDobOq/3IT6qEgDUYhj2YNQKyV0/VooQmho 53BQBW0/kLx2EDzS2jpzQnaxOjKBhGGW2QRvTgGdW1/3M+NQ/WJUqgeh/5rRoea/ CxKdIO+ybREZ1IUjN7LtUB8sdvA== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vgxxbhtdx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 19:37:59 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409JbwSp011941 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 19:37:58 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; Tue, 9 Jan 2024 11:37:57 -0800 From: Elliot Berman Date: Tue, 9 Jan 2024 11:37:52 -0800 Subject: [PATCH v16 14/34] virt: gunyah: Add hypercalls for running a vCPU Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20240109-gunyah-v16-14-634904bf4ce9@quicinc.com> References: <20240109-gunyah-v16-0-634904bf4ce9@quicinc.com> In-Reply-To: <20240109-gunyah-v16-0-634904bf4ce9@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.13-dev 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: wCModZ2NGEmXJVf9EloG8vARBtmLpUR5 X-Proofpoint-GUID: wCModZ2NGEmXJVf9EloG8vARBtmLpUR5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=446 lowpriorityscore=0 priorityscore=1501 bulkscore=0 phishscore=0 spamscore=0 clxscore=1015 mlxscore=0 adultscore=0 impostorscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090158 Add hypercall to donate CPU time to a vCPU. Signed-off-by: Elliot Berman --- arch/arm64/gunyah/gunyah_hypercall.c | 37 ++++++++++++++++++++++++++++++++++++ include/linux/gunyah.h | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/arch/arm64/gunyah/gunyah_hypercall.c b/arch/arm64/gunyah/gunyah_hypercall.c index 1302e128be6e..fee21df42c17 100644 --- a/arch/arm64/gunyah/gunyah_hypercall.c +++ b/arch/arm64/gunyah/gunyah_hypercall.c @@ -39,6 +39,7 @@ EXPORT_SYMBOL_GPL(arch_is_gunyah_guest); #define GUNYAH_HYPERCALL_HYP_IDENTIFY GUNYAH_HYPERCALL(0x8000) #define GUNYAH_HYPERCALL_MSGQ_SEND GUNYAH_HYPERCALL(0x801B) #define GUNYAH_HYPERCALL_MSGQ_RECV GUNYAH_HYPERCALL(0x801C) +#define GUNYAH_HYPERCALL_VCPU_RUN GUNYAH_HYPERCALL(0x8065) /* clang-format on */ /** @@ -113,5 +114,41 @@ enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size, } EXPORT_SYMBOL_GPL(gunyah_hypercall_msgq_recv); +/** + * gunyah_hypercall_vcpu_run() - Donate CPU time to a vcpu + * @capid: capability ID of the vCPU to run + * @resume_data: Array of 3 state-specific resume data + * @resp: Filled reason why vCPU exited when return value is GUNYAH_ERROR_OK + * + * See also: + * https://github.com/quic/gunyah-hypervisor/blob/develop/docs/api/gunyah_api.md#run-a-proxy-scheduled-vcpu-thread + */ +enum gunyah_error +gunyah_hypercall_vcpu_run(u64 capid, unsigned long *resume_data, + struct gunyah_hypercall_vcpu_run_resp *resp) +{ + struct arm_smccc_1_2_regs args = { + .a0 = GUNYAH_HYPERCALL_VCPU_RUN, + .a1 = capid, + .a2 = resume_data[0], + .a3 = resume_data[1], + .a4 = resume_data[2], + /* C language says this will be implictly zero. Gunyah requires 0, so be explicit */ + .a5 = 0, + }; + struct arm_smccc_1_2_regs res; + + arm_smccc_1_2_hvc(&args, &res); + if (res.a0 == GUNYAH_ERROR_OK) { + resp->sized_state = res.a1; + resp->state_data[0] = res.a2; + resp->state_data[1] = res.a3; + resp->state_data[2] = res.a4; + } + + return res.a0; +} +EXPORT_SYMBOL_GPL(gunyah_hypercall_vcpu_run); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls"); diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 359cd63b4938..8405b2faf774 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -274,4 +274,39 @@ enum gunyah_error gunyah_hypercall_msgq_send(u64 capid, size_t size, void *buff, enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size, size_t *recv_size, bool *ready); +struct gunyah_hypercall_vcpu_run_resp { + union { + enum { + /* clang-format off */ + /* VCPU is ready to run */ + GUNYAH_VCPU_STATE_READY = 0, + /* VCPU is sleeping until an interrupt arrives */ + GUNYAH_VCPU_STATE_EXPECTS_WAKEUP = 1, + /* VCPU is powered off */ + GUNYAH_VCPU_STATE_POWERED_OFF = 2, + /* VCPU is blocked in EL2 for unspecified reason */ + GUNYAH_VCPU_STATE_BLOCKED = 3, + /* VCPU has returned for MMIO READ */ + GUNYAH_VCPU_ADDRSPACE_VMMIO_READ = 4, + /* VCPU has returned for MMIO WRITE */ + GUNYAH_VCPU_ADDRSPACE_VMMIO_WRITE = 5, + /* VCPU blocked on fault where we can demand page */ + GUNYAH_VCPU_ADDRSPACE_PAGE_FAULT = 7, + /* clang-format on */ + } state; + u64 sized_state; + }; + u64 state_data[3]; +}; + +enum { + GUNYAH_ADDRSPACE_VMMIO_ACTION_EMULATE = 0, + GUNYAH_ADDRSPACE_VMMIO_ACTION_RETRY = 1, + GUNYAH_ADDRSPACE_VMMIO_ACTION_FAULT = 2, +}; + +enum gunyah_error +gunyah_hypercall_vcpu_run(u64 capid, unsigned long *resume_data, + struct gunyah_hypercall_vcpu_run_resp *resp); + #endif -- 2.34.1