From patchwork Tue Jun 7 20:32:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 579322 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp5491176max; Tue, 7 Jun 2022 13:36:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjqui08rG3dN7x9hHPM/P7Hf6g2ZvztTjjcvw42eu4DcyM4vwncAnaKzCd+jbW+hm3RGhD X-Received: by 2002:a05:622a:2cf:b0:2f9:399e:cee0 with SMTP id a15-20020a05622a02cf00b002f9399ecee0mr24440281qtx.412.1654634198958; Tue, 07 Jun 2022 13:36:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654634198; cv=none; d=google.com; s=arc-20160816; b=jw0olCrsv56EUWCzT7TdWzr18G+SrZcuB+88Cs57jjOO9V+qF8/Is6OKYdxZ+WmJho P1kuXATTy/EmDp16imFfXxNZ9zeIgSCqMCE7RMs+7BSszxRVeGoYulOEbtIDoZdpTiwu TPHD1TQkXxzxqyyM+Iw49BjtzEH5hr+40/3djN8Ew1ALgUHkwuhkrxuJ5/ZHZ+qfS7oN b6utEv31NemfDCwk1mnqPQIZwx6Vx+a+pJxMPohm4njsy3kZxUpmaCJNICqciclPb4PF M8en9LJ64TyqRPchz5riDPK8OtQzgIcfIKuGNMUx9No2+zh/kMDeckBCesAjYJ6f2ouG mAgA== 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=bgSSWj3FWGjqqOHg3NGXEoGoqiXuSmAzBvkeO1FtIzY=; b=KlPtrVQXhWoj9Qyi4o9Sltndox+aO8uGCksdbNv97Lu9Km7XoaahzVbvubzDOAkyOz UmkGz/MA0R9TBdVNfCkVR5iNpDpUxBRzTC0vG8rh0GkUpildjcKZqe0m7ShhS8vR7Ip0 JkEImWvy8X+Y0nMZXpQefkIVhcwVNT2ONTz3j7UKO6z0jYnhlspJatrduPS+e/mXb4A6 9GZuKotQFHO/9kzpEUzo06RM8YYYqbDg1vPqsVyia6ZmQx74fTbMm6XlbuKePGrO7JS1 BvMNIczMagS4zhExbkrr1gwnGKqb5QVh4dFLD7R3XWEn7Y6WSdGwryFA4dXBP2+gZuh3 0NXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WQfeqX1U; 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 hr14-20020a05621423ce00b0045acf12507fsi9724058qvb.296.2022.06.07.13.36.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Jun 2022 13:36:38 -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=WQfeqX1U; 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]:46532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyfwL-0003Z2-Cz for patch@linaro.org; Tue, 07 Jun 2022 16:36:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyft7-0007HV-7U for qemu-devel@nongnu.org; Tue, 07 Jun 2022 16:33:17 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:53042) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyft3-0007Df-LN for qemu-devel@nongnu.org; Tue, 07 Jun 2022 16:33:16 -0400 Received: by mail-pj1-x1032.google.com with SMTP id gd1so16669569pjb.2 for ; Tue, 07 Jun 2022 13:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bgSSWj3FWGjqqOHg3NGXEoGoqiXuSmAzBvkeO1FtIzY=; b=WQfeqX1U+IFBpsPRJTcz748nuIuq87IcS6s8MhUOl8rTJ8kk68tIQyEP4guqvNB8dp VUymy3PVaIsPJSUqaBAG1XsWLAVz9WrFu1MIYMxTNw1t0SlZGA6XThZGhIqe8rUsZJoO 3+W7xxRqmmZcxFcawoH+Utc6BhOanbPqSm2O57Zvvu3zHGyy9QmrJZ30D57X7WChu59K c88XOwMrB8es88jk9DKGjT/HDUKTTtroasiEjvx5hQOEh0SxZUz85HoehAjLRNZQ5hMc tGJTPRNxMn9sv8KZ+GRxRO3t4wgmNVzbGakXsLwtTqyRfKiSpMo1Q1ZHrP2iZOxUR/kw vA8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bgSSWj3FWGjqqOHg3NGXEoGoqiXuSmAzBvkeO1FtIzY=; b=uHugxMOgDhLDy7tEJMKZUinAw/w296wvKrA3DVQhPAdpWahimMC7Gg9ZaMXEDyMyPD gIZJCc9Kzag6Dw6Nq18PDp7+lhFd4TGwcSOL+xL6mPGO81/jy+XoNZKlts5SM1zwRO2w yrnlZHQWOFRUy7vOwgc6+ll2PqKutAlg7KX3s3AaxI9/e9h/RYe2kRkxdPngx8V1dyod xhljBL+CpNbruKjfUrXQiPS2LRNTYJgHRSWMlZgTb4OmpAryHcIByRPya8i3vTKjrMow qe0FZ1Y/0EPoksUEd3ARXxbsGaauIKaJP2R+YCRbDSAu+Nu2PlVlbvjogi1FdW114ksY v89w== X-Gm-Message-State: AOAM530RGly2YKG4tmWbibUnC5bjJxAtDD1Vj4nFIYQATCGh/Jpw6wQk mIVuY448iuRrT4oV7S038GWQkDmvf5hS+w== X-Received: by 2002:a17:903:41d0:b0:167:68a7:c2f with SMTP id u16-20020a17090341d000b0016768a70c2fmr17693386ple.148.1654633992263; Tue, 07 Jun 2022 13:33:12 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3cf2:c634:5b19:25f6]) by smtp.gmail.com with ESMTPSA id s22-20020a17090aba1600b001d9780b7779sm4227856pjr.15.2022.06.07.13.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 13:33:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org Subject: [PATCH v2 05/71] target/arm: Add el_is_in_host Date: Tue, 7 Jun 2022 13:32:00 -0700 Message-Id: <20220607203306.657998-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607203306.657998-1-richard.henderson@linaro.org> References: <20220607203306.657998-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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, T_SCC_BODY_TEXT_LINE=-0.01 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" This (newish) ARM pseudocode function is easier to work with than open-coded tests for HCR_E2H etc. Use of the function will be staged into the code base in parts. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/internals.h | 2 ++ target/arm/helper.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/target/arm/internals.h b/target/arm/internals.h index b654bee468..a73f2a94c5 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1328,6 +1328,8 @@ static inline void define_cortex_a72_a57_a53_cp_reginfo(ARMCPU *cpu) { } void define_cortex_a72_a57_a53_cp_reginfo(ARMCPU *cpu); #endif +bool el_is_in_host(CPUARMState *env, int el); + void aa32_max_features(ARMCPU *cpu); #endif diff --git a/target/arm/helper.c b/target/arm/helper.c index bcf48f1b11..839d6401b0 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5292,6 +5292,34 @@ uint64_t arm_hcr_el2_eff(CPUARMState *env) return ret; } +/* + * Corresponds to ARM pseudocode function ELIsInHost(). + */ +bool el_is_in_host(CPUARMState *env, int el) +{ + uint64_t mask; + + /* + * Since we only care about E2H and TGE, we can skip arm_hcr_el2_eff(). + * Perform the simplest bit tests first, and validate EL2 afterward. + */ + if (el & 1) { + return false; /* EL1 or EL3 */ + } + + /* + * Note that hcr_write() checks isar_feature_aa64_vh(), + * aka HaveVirtHostExt(), in allowing HCR_E2H to be set. + */ + mask = el ? HCR_E2H : HCR_E2H | HCR_TGE; + if ((env->cp15.hcr_el2 & mask) != mask) { + return false; + } + + /* TGE and/or E2H set: double check those bits are currently legal. */ + return arm_is_el2_enabled(env) && arm_el_is_aa64(env, 2); +} + static void hcrx_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) {