From patchwork Sat Oct 1 16:22:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 611389 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp277584pvb; Sat, 1 Oct 2022 09:38:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4zxn8ybeUG4C+GWhLEO7pa631iEBmTAQjTfuC94hiVQ41RfFjhgdq6esSyslxcvp1k5Gkz X-Received: by 2002:a05:620a:11ab:b0:6ce:5fb5:a8dc with SMTP id c11-20020a05620a11ab00b006ce5fb5a8dcmr9215103qkk.137.1664642295006; Sat, 01 Oct 2022 09:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664642295; cv=none; d=google.com; s=arc-20160816; b=jsvsl2KnTBeaVwequy0ulbClWPgm1RIE6MdNHuYPQw9xyNECcVgL9eN4bUMtIL4x0u wmcS52gXaUoMpm/hQ2LmrDwAn0wXPKRNFWftYal6jg6/DCLa+uHNAnuK75V8/6q+S4WA D+5yThevCQP0W5P0Hdr32szKRjjn5ZnwJ+VlnW88hnvQ9V8HEpCJJtGhY+Y5yRjl9gY1 WlFp5iJ3Pu+5+gYlgGOIcN+nnn17lqJzaDaCVxmmCVSmBTACNtqFyFajUBv3+WIB+QDd Ela7e2kX4on6Dvo4WHzEdiZXCqfPd08eQfLeL4wLBHlOKOmXSMspYutsB5q/ZSJoME1z tGXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7gsclz+yJ1LC9lf4uAjmiJKG45xyG8DkF/pgWvR4z/U=; b=AlWDerxIagJG+E4nVqJzhBbGF9zKu9Tv7v8BgWVGZGDYz+82mEKcA2KrDAjBMr2aNx 5s6Q+Ot/ZYz5FylEIqojcy7pA3BBezCc6shSPNR6zcTdYs1KDd7CNDOesDa4pLimWxLN DeeGw2dv2xBoN3KjR9LZCU23Zm3fopkaXGgsbjhLCp9um+EBxDraK29mZrgX09cHAip/ dQ0ykXCAO4U/OueKQIt7See79n8pY8DijGX87gGno/Di70dycy2ky2nnWSFJY6RpJHZo ZdpODFVlZCv3PDJY76hq5EpiChqrZaI8KhF6QeZEFZVhK8Un2q8vwsI6yQtIeaEbT5kg 4GXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OhjW+ZSO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z18-20020ac875d2000000b0035bcfa074a1si2490465qtq.212.2022.10.01.09.38.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Oct 2022 09:38:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OhjW+ZSO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oefVG-0007u8-H8 for patch@linaro.org; Sat, 01 Oct 2022 12:38:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oefHW-0006kT-8k for qemu-devel@nongnu.org; Sat, 01 Oct 2022 12:24:05 -0400 Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]:46075) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oefHQ-0006HO-EF for qemu-devel@nongnu.org; Sat, 01 Oct 2022 12:24:00 -0400 Received: by mail-qv1-xf32.google.com with SMTP id g9so834498qvo.12 for ; Sat, 01 Oct 2022 09:23:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=7gsclz+yJ1LC9lf4uAjmiJKG45xyG8DkF/pgWvR4z/U=; b=OhjW+ZSOGIbPYAfy2rXRKqigSG+IVjzfqEgCODIMYJ0nhqT5sFZ8iyUOz0nlvaj/s5 xhNYdAZSM5G1O9EtPPxT8xNS2M1uSvPDLJ2SN/KN0INYsWaUWgjzaFdsZlsbr3ddPCQS bfEiKpZSe0f6JMAuJlk4/wQRMv73NgjqUV1jE/+ri8TaCTl9mA20zd4IWaB5+xbgkdHu ICYmR5X3XV9lkAJ5i5aM0j61lyL/oeANjNb1/6WdVyaE+trBp+FYCMDleHYRH3l7aRqK C2jUgjb+/ZGS0vik+dYBtmdHyfiKd+zHHXQLwVvOIzCGCABGnFt64B8vWt1MECjSqmke k/cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=7gsclz+yJ1LC9lf4uAjmiJKG45xyG8DkF/pgWvR4z/U=; b=01e520FgOK5O8if597tllYyypB24DbEYwOFpdzYRzncUMhIW3VSZDL4wODqqCPAQnQ BVdGbyUdeHthuRtEmdVW1lyGBO+QEF5B6jfpoiX3nUapka7wgYnpPbiL8GDRJzZ6t4nf aKhTi5caKyRCWI2vwpTmAM+PDBewmKizbWPVMgOsa0WVBVsJsOErNN4/zoNgcm4Bi1Rf RsEJva15CmPL8hQCRBOlmpnFdKkf9JDhtpTXFeSdtGyaPOp7x/gwN9Ohuu4+1VvALkRW tw8Vwtm382MZIL7QHC7ocgBnHp/QY8t5kAotJyNXLu59BdlscZKRuhbj0LWR7mptAi3b OVGw== X-Gm-Message-State: ACrzQf32bL54cJO1XHP4CmfpsAIbzxnMMnIuHhC4+HHjUgaVSCBWjKv6 PYnKpJ/7byNjm450XchYThN9RpKm6BKUvg== X-Received: by 2002:ad4:5c6c:0:b0:4b1:7030:b195 with SMTP id i12-20020ad45c6c000000b004b17030b195mr5809218qvh.107.1664641434351; Sat, 01 Oct 2022 09:23:54 -0700 (PDT) Received: from stoup.. ([2605:ef80:8084:91a4:f7cb:db31:c505:b931]) by smtp.gmail.com with ESMTPSA id t4-20020a37ea04000000b006d1d8fdea8asm4387445qkj.85.2022.10.01.09.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:23:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v3 13/42] target/arm: Introduce arm_hcr_el2_eff_secstate Date: Sat, 1 Oct 2022 09:22:49 -0700 Message-Id: <20221001162318.153420-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221001162318.153420-1-richard.henderson@linaro.org> References: <20221001162318.153420-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f32; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For page walking, we may require HCR for a security state that is not "current". Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 20 +++++++++++++------- target/arm/helper.c | 11 ++++++++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 6475dc0cfd..0f82f4aa1d 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2406,15 +2406,15 @@ static inline bool arm_is_secure(CPUARMState *env) * Return true if the current security state has AArch64 EL2 or AArch32 Hyp. * This corresponds to the pseudocode EL2Enabled() */ +static inline bool arm_is_el2_enabled_secstate(CPUARMState *env, bool secure) +{ + return arm_feature(env, ARM_FEATURE_EL2) + && (!secure || (env->cp15.scr_el3 & SCR_EEL2)); +} + static inline bool arm_is_el2_enabled(CPUARMState *env) { - if (arm_feature(env, ARM_FEATURE_EL2)) { - if (arm_is_secure_below_el3(env)) { - return (env->cp15.scr_el3 & SCR_EEL2) != 0; - } - return true; - } - return false; + return arm_is_el2_enabled_secstate(env, arm_is_secure_below_el3(env)); } #else @@ -2428,6 +2428,11 @@ static inline bool arm_is_secure(CPUARMState *env) return false; } +static inline bool arm_is_el2_enabled_secstate(CPUARMState *env, bool secure) +{ + return false; +} + static inline bool arm_is_el2_enabled(CPUARMState *env) { return false; @@ -2440,6 +2445,7 @@ static inline bool arm_is_el2_enabled(CPUARMState *env) * "for all purposes other than a direct read or write access of HCR_EL2." * Not included here is HCR_RW. */ +uint64_t arm_hcr_el2_eff_secstate(CPUARMState *env, bool secure); uint64_t arm_hcr_el2_eff(CPUARMState *env); uint64_t arm_hcrx_el2_eff(CPUARMState *env); diff --git a/target/arm/helper.c b/target/arm/helper.c index 0fd0c73092..4eec22b1f8 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5216,15 +5216,15 @@ static void hcr_writelow(CPUARMState *env, const ARMCPRegInfo *ri, } /* - * Return the effective value of HCR_EL2. + * Return the effective value of HCR_EL2, at the given security state. * Bits that are not included here: * RW (read from SCR_EL3.RW as needed) */ -uint64_t arm_hcr_el2_eff(CPUARMState *env) +uint64_t arm_hcr_el2_eff_secstate(CPUARMState *env, bool secure) { uint64_t ret = env->cp15.hcr_el2; - if (!arm_is_el2_enabled(env)) { + if (!arm_is_el2_enabled_secstate(env, secure)) { /* * "This register has no effect if EL2 is not enabled in the * current Security state". This is ARMv8.4-SecEL2 speak for @@ -5283,6 +5283,11 @@ uint64_t arm_hcr_el2_eff(CPUARMState *env) return ret; } +uint64_t arm_hcr_el2_eff(CPUARMState *env) +{ + return arm_hcr_el2_eff_secstate(env, arm_is_secure_below_el3(env)); +} + /* * Corresponds to ARM pseudocode function ELIsInHost(). */