From patchwork Tue May 17 05:48:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 573440 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp118080mab; Mon, 16 May 2022 23:04:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJT3Fa7Q/o3AM9zIpR3q1Mv4vkMC82YftRizyYHC/Yrpkw3lU61wRwLKFsAy7fCzwjEUog X-Received: by 2002:ad4:5c8f:0:b0:456:3dbf:f58e with SMTP id o15-20020ad45c8f000000b004563dbff58emr18691205qvh.37.1652767450902; Mon, 16 May 2022 23:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652767450; cv=none; d=google.com; s=arc-20160816; b=RfRpSOct14yjeW9tY3+vLFuWNeTgx9RwFtVwN8CkWh5AmUMCyZRxMAhT36yM/L963t 356rj7chfr5yyOgtn5WAoRaF2M3Kz3LCmifAnk2Bz5Gn2MEzWDPVBI9cGHiTAB9xg05r WmflZegVdB1KM5oVZ6dFCgteOKFKsYrYPBWZPLnn2/2LhQXm632OI8bdz2Qj3FmXv63a BXkSdByo71WixX4NPwkHC6ertQdw7AIRCB7MySASu26VH9MJ2Yk8d7d19ijbSUZ97yuV EQEN71eN6jlXyc78J9MV90OcOBFcAUwRFUS5AJT4oISBl/cORtfzZBeABdZkF1NSwKfJ CNMg== 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=QZWPLUoqPQwRNEP7N/mQ6KcZy+VCmkdoHNOMQdySREE=; b=y0pt16knZYKYBGajqkb1nOji85RSsmXlrXl98/hS3/HVbLm06IPQMCgj6hmRLoJQey DgsTtP+rKXa98FFmSxc/Fe/htohR13VGDi3mwGx/V1vnSFfB6rpZw7t8SexgNGQj24xi Rcaq1MeMQDqx+uD+APo/TxOk8lQ7RxtVQ2B2oN3c1NBYN+T1zr4nQkedFUxqlx66O5sc KNa1Zu7PeRgIZfciCppAHtF4AO1kc1oh/HfE+Yp9ScgNeXmVPMx4h1InIsilucsEulPD KFvUFgeczEj5lvuydQYmJw48bydpR8ONvdoZBokJebpXVnqkEXwUhda/FMumzUgtrCE7 IekA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BBhBZtGR; 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 bi39-20020a05620a31a700b006a2ee695d24si3746875qkb.761.2022.05.16.23.04.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 May 2022 23:04:10 -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=BBhBZtGR; 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]:53256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqqJW-0002Tn-Dk for patch@linaro.org; Tue, 17 May 2022 02:04:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqq4r-0000UA-GS for qemu-devel@nongnu.org; Tue, 17 May 2022 01:49:04 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:37525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nqq4o-0007on-Rk for qemu-devel@nongnu.org; Tue, 17 May 2022 01:49:01 -0400 Received: by mail-pl1-x629.google.com with SMTP id m12so16441134plb.4 for ; Mon, 16 May 2022 22:48:58 -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=QZWPLUoqPQwRNEP7N/mQ6KcZy+VCmkdoHNOMQdySREE=; b=BBhBZtGRqYUcaXBpG3+7zdUq4zM39qyTm8nURSTNIjHnbz5pOkzIcYC8RxCzIp47+v TAkGa/N0jhmz8Ym/9EFVaBZ5DouqalXAQLRPY825oBFCIs0kc74X7gKGW30qdlhkws2H AVM3G7vPwrjCXqkalrqsPgYJTcN/J0hyxpAQfCp46T73V0f+zDYVyD+wss21NAO1sIXS EGP2LnsobAhFODS2UmKccGdbeVCNAKDweB8u8LKJMJJHIVxeXJETn1zxdWP3qvzZJ6dg qNL4TVLKcN8ouc2IIiFLsji3tGFdKpI4JnLpKYG+Jd2nVZX5rc3haGGPpwVMcjrfim1t Q11Q== 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=QZWPLUoqPQwRNEP7N/mQ6KcZy+VCmkdoHNOMQdySREE=; b=44yP5asN09NTcI7ivOZo16gg5owFpx9+f7acaFS/opf9b4Cx9Nc3Jl7RFxUXw8Kqhg WwLd9TXHg+/cblv3oRlZLpKT6xRYxtLNQjhOQk/ar1qISf8vfibLURodRk2iIetleaaK BT9NVnXDXzZ5JOeCkWPTMiEtg/Xy5Va9sMFdIkshpX9OFFbd9S4+YHBBWoeq92bjXm35 149am45BP78eWGb64KTP1+0++7807d/xK7mkeZxpnhrC54UBc96wIC68/JPzxR7dMBmN sBym4cTTEsF8BNfar4wn+dR1roGiaNEMdYXPEXqPXvVm23GwC8SFwVK63WNKw1tiMG8o PMHg== X-Gm-Message-State: AOAM532ECQH+/mLVGq7bTOQX4X7O45M6LIE83+OeyKEs3szReOudeYt0 17Iij01RkZ0xegdcBZwQNrYrsZDZN2V86Q== X-Received: by 2002:a17:90b:35cc:b0:1df:8218:a427 with SMTP id nb12-20020a17090b35cc00b001df8218a427mr2478553pjb.15.1652766537541; Mon, 16 May 2022 22:48:57 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id b12-20020a170902d88c00b0015e8d4eb1fasm8146670plz.68.2022.05.16.22.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 22:48:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 7/7] target/arm: Add el_is_in_host Date: Mon, 16 May 2022 22:48:50 -0700 Message-Id: <20220517054850.177016-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220517054850.177016-1-richard.henderson@linaro.org> References: <20220517054850.177016-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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. Signed-off-by: Richard Henderson --- target/arm/internals.h | 2 ++ target/arm/helper.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/target/arm/internals.h b/target/arm/internals.h index 4165d49570..58392c8246 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1310,6 +1310,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); /* Powers of 2 for sve_vq_map et al. */ diff --git a/target/arm/helper.c b/target/arm/helper.c index 05baa73986..d082a1cf18 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5282,6 +5282,29 @@ 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 */ + } + + 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) {