From nobody Fri May 3 12:07:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505721206954590.4782005043737; Mon, 18 Sep 2017 00:53:26 -0700 (PDT) Received: from localhost ([::1]:35123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtqru-0005W8-0v for importer@patchew.org; Mon, 18 Sep 2017 03:53:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtqq5-0004S6-6l for qemu-devel@nongnu.org; Mon, 18 Sep 2017 03:51:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtqq2-0002xJ-4M for qemu-devel@nongnu.org; Mon, 18 Sep 2017 03:51:33 -0400 Received: from goliath.siemens.de ([192.35.17.28]:50714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dtqq1-0002wq-PT for qemu-devel@nongnu.org; Mon, 18 Sep 2017 03:51:30 -0400 Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id v8I7pS3q028395 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Sep 2017 09:51:28 +0200 Received: from md1f2u6c.ww002.siemens.net ([139.22.134.132]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id v8I7pRHR032566; Mon, 18 Sep 2017 09:51:27 +0200 To: Peter Maydell , qemu-devel From: Jan Kiszka Message-ID: <1d61ec4d-da94-e96a-e1f6-509a4e80daec@siemens.com> Date: Mon, 18 Sep 2017 09:51:27 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 192.35.17.28 Subject: [Qemu-devel] [PATCH] arm: Fix SMC reporting to EL2 when QEMU provides PSCI X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Jan Kiszka This properly forwards SMC events to EL2 when PSCI is provided by QEMU itself and, thus, ARM_FEATURE_EL3 is off. Found and tested with the Jailhouse hypervisor. Signed-off-by: Jan Kiszka --- target/arm/helper.c | 2 +- target/arm/op_helper.c | 8 ++++---- target/arm/psci.c | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 4f41841ef6..8c3929762c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -3717,7 +3717,7 @@ static void hcr_write(CPUARMState *env, const ARMCPRe= gInfo *ri, uint64_t value) =20 if (arm_feature(env, ARM_FEATURE_EL3)) { valid_mask &=3D ~HCR_HCD; - } else { + } else if (cpu->psci_conduit !=3D QEMU_PSCI_CONDUIT_SMC) { valid_mask &=3D ~HCR_TSC; } =20 diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index 6a60464ab9..4b0ef6a234 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -960,12 +960,12 @@ void HELPER(pre_smc)(CPUARMState *env, uint32_t syndr= ome) return; } =20 - if (!arm_feature(env, ARM_FEATURE_EL3)) { - /* If we have no EL3 then SMC always UNDEFs */ - undef =3D true; - } else if (!secure && cur_el =3D=3D 1 && (env->cp15.hcr_el2 & HCR_TSC)= ) { + if (!secure && cur_el =3D=3D 1 && (env->cp15.hcr_el2 & HCR_TSC)) { /* In NS EL1, HCR controlled routing to EL2 has priority over SMD.= */ raise_exception(env, EXCP_HYP_TRAP, syndrome, 2); + } else if (!arm_feature(env, ARM_FEATURE_EL3)) { + /* If we have no EL3 then SMC always UNDEFs */ + undef =3D true; } =20 if (undef) { diff --git a/target/arm/psci.c b/target/arm/psci.c index fc34b263d3..637987ff46 100644 --- a/target/arm/psci.c +++ b/target/arm/psci.c @@ -35,6 +35,8 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type) */ CPUARMState *env =3D &cpu->env; uint64_t param =3D is_a64(env) ? env->xregs[0] : env->regs[0]; + int cur_el =3D arm_current_el(env); + bool secure =3D arm_is_secure(env); =20 switch (excp_type) { case EXCP_HVC: @@ -46,6 +48,10 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type) if (cpu->psci_conduit !=3D QEMU_PSCI_CONDUIT_SMC) { return false; } + if (!secure && cur_el =3D=3D 1 && (env->cp15.hcr_el2 & HCR_TSC)) { + /* The EL2 will handle this. */ + return false; + } break; default: return false; --=20 2.12.3