Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp647483rdb; Thu, 22 Feb 2024 15:17:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVpnnvwOQsx+lKqIrloVWtsCsK/eJa8sDX235++YSlToF+eZH1RebHTOg8C2T5v60sCbYE0P4louh9Swp8dzdLa5tuB8J5QSh3FVH91iQ== X-Google-Smtp-Source: AGHT+IHEflZNDQASx9BwCCxUZPTeAlX0jvB0Ih1j45jEAznwMM+amvhn9g/P9zXOT7cBYF0BYSuq X-Received: by 2002:a17:902:a384:b0:1db:ca53:41d with SMTP id x4-20020a170902a38400b001dbca53041dmr253295pla.31.1708643851007; Thu, 22 Feb 2024 15:17:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708643850; cv=pass; d=google.com; s=arc-20160816; b=vG4cME7V1qzlq7ZC47tYca4PgoEuKRHgyCsxs7kbb1MGk7Jb11rZnwsy3JCBShZ4Vu Bg/nN5q4FOVSLgC6CBSLf3DunvPu6Og8wTnDS1xvHs0bNQB39zmc7WfAnMmM78RcNIG2 QUJCCpf4WGYbxUMEFdEwlNgH0alUpSP0lOm8OG1Uj9DI7p254VFvmGK2pmWcCfsFB8oK t8Tpt6GvzoaPFuc1vV06HsEa4R6blxnkk2ucKmrBGftUXuvPWNuIo41g+d5O4qvPjIet lHTeiBcA4qvm2w8NuXXuPLjaDgjoCZNALE6kaDkBHzIeSqFcraGryvy9v23dxpUQSogM FIUA== ARC-Message-Signature: i=2; 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=qpqdFemGGFJkjOEURdTOzVY4PBnSlU3kwov4k+Wn9r0=; fh=j53ffieBeHmuArQHAkiXDczYOIriM+Jf92hqYE3BW8U=; b=hsf8Rv+FppVp2OqU98n3mIXIPLsRRfA07a42JzDAgjDFgbrTqXK+hM40b1r43+rM86 6pvDljyl4dzU3ROFV8F88cnk9Dh+A9rMaAQ0XXH9AJnwMkdxSB1XaIj65RUEqR7x2NM3 5uikfDJPs3vFrOAQymsVGTjGfkr1xSSemu2ncyRIQo3XrRssgexWi+QSbThIV98uYtcO pnKGWFrB8q4ERLizc85TDkIHjFlPjYWhg5/y0amN8B78GB1CiJuibGF9By5pL/fX0oBe 63kgzlGiddn7ID7wZC1isPCIsKm3uztnli40NJGYXtGh3nIcGSCOLcEHqUOOjUxV5iDx LH3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=We7DYilB; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-77494-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77494-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e19-20020a170902ed9300b001db5b403704si10467787plj.313.2024.02.22.15.17.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 15:17:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77494-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=We7DYilB; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-77494-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77494-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 46140B212FF for ; Thu, 22 Feb 2024 23:17:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78BB322301; Thu, 22 Feb 2024 23:17:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="We7DYilB" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 BAFDD18629; Thu, 22 Feb 2024 23:17:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708643822; cv=none; b=s2PNhx+DFpw1MJFhw4gq2Bw1Bl4Y0JJxv/MYSf9y4wN9hYRAKez+DKWagvruqRd7wZiZizOXvqchg+9u7iDYV9ZiH0FxE2opTDcTPrXZTkuyDLLi5bOqP9pXdHBIm6XSRLjH6zDplEch/1N2p8mR0OyQmZ7VqX7M5P29+B8XyAo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708643822; c=relaxed/simple; bh=nQZaS7M9yWdAiGBXVD4d2qZb20NwyLN1XC2dnRAcwu4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=Jn3CBmg/HE9McPvTdnr7OCS4vAaPyednkzK7J9dW0yUXEzBK01kK1vqZVkLtEW5G7nVR4X4cLZLrKnnTKYIHDG7Cmy4QQeGXQOpTAgbYZ2mNurbepIOZBIOnKfz3+6OW4X++T2EO7tri/wVjNFwEz2fTdGKTpFCnpPM26T04Zeo= 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=We7DYilB; arc=none smtp.client-ip=205.220.180.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 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MLiPtL021602; Thu, 22 Feb 2024 23:16:36 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=qpqdFemGGFJkjOEURdTOzVY4PBnSlU3kwov4k+Wn9r0 =; b=We7DYilBpy08K7/xknPD35U3nqsWufZYKODVFk2NxJd+u8ZVF7g56A+9QAU 9LUwNK/gmcLOt4HmdTA5BspuBTaY3mXnAjcuZSuZ6aCH2t1vWe03jedAvPNT9NoV m8SXoEbo7XQVxRN7xmAwc733zu5U+4cfFPnmRATuNhqgXrqJnvsxEMX7H+uwUqQb SfQNfcyDjAVK+GvP3x/szQn+pPOgSzqbBSQxq8lrTeUc/VNXuwyVsgnpK+M+T6RZ 308XBsyk1CICW2pjJi54++2MSIifBLyTt3y+a/gaXTlyWvCuIxakQdt1Zbyore3N zeM1HfksjMEta/6iKltfSQ5noDQ== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we2kf9puj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:36 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGZjM017474 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:35 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:34 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:37 -0800 Subject: [PATCH v17 14/35] 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: <20240222-gunyah-v17-14-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: 1Ifkr26tkeB9TdkcC50PB1_JgTfOYFy7 X-Proofpoint-GUID: 1Ifkr26tkeB9TdkcC50PB1_JgTfOYFy7 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 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=0 phishscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=556 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 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 1302e128be6e9..fee21df42c176 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 18ecebf41a3ff..6c24544f38dc9 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -273,4 +273,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