From patchwork Fri Jan 27 17:54:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 647515 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp959844pvb; Fri, 27 Jan 2023 09:57:26 -0800 (PST) X-Google-Smtp-Source: AK7set/3FP0qNf8VYZqQchQFMKnUDnJg1JDFIxaXK9BjUqDOUqdf6OxkXPbzJQObQotzaFCiyOOT X-Received: by 2002:ac8:7dca:0:b0:3b8:26a1:956f with SMTP id c10-20020ac87dca000000b003b826a1956fmr3745582qte.17.1674842246591; Fri, 27 Jan 2023 09:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674842246; cv=none; d=google.com; s=arc-20160816; b=DFY+4muHeB1y+bbwHWv83XeV4FCC+KRmrKEKWHwhstTIpihIUsEe+k6zendHfZ3kZy 9In4RksdmwWx+WLbfl4wTT2+sv8aT5D+d00p10MFcMZFHBgbCl+IMVyKhborAdjFZruP lgZFe6qUqcOeX/q+nz7FCuOjfrztBaZ57WPlvGr8uYWWKea+7Eyv60oUffxsE3zkEG3M MWGZ2dtEueB0T4XYCZ+mOEI10GSHsu4Rd4WozgGHIwOYQvjQY8A0cwIqJle8oVcgFX48 dhPmrSfL5abV6rJqJBJWeoKbsuXQ1uhtLHEAldcxB46Id7kc2nW/rRDnAlgfOTG1cgqB 9KSQ== 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:to:from :dkim-signature; bh=HS55RKKRetN93F2NWMHY8F2JBNqkHa0rbeTZy521S+g=; b=NTb5zgMUB7epYwjAbZ/ToVbu/CFc9F1zPXbQn96zgNN8StfA7x9mY4R0PEc6/v/X5X nYsm/qP+sZ4s3qwIH7wyMORw1FAsrBWcTvSa3LDi+n0FxNQHYDEbDYROcREnxeO6I+1F qHn0j1kiAYNTaC6DDAVMu+cPvVxJPdPAi5p0Ila0pEIDjLLBA7BllyZO5/RSJOloXNjT lfNJ+90Zyk+z0WumAEDkx71Ov7RjrA44aEdDtQV/MihbIfhIQvFsrhalxrzv+g/cJLWl WJTug5ZF/8eoLzybriVpCRXsDB4egiksxY9fwEylxybD3RwuO0sfMphVwVqy6AAJ5IZI N2Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BTOuE5ym; 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 15-20020ac8594f000000b003b68e838520si3066898qtz.639.2023.01.27.09.57.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 27 Jan 2023 09:57:26 -0800 (PST) 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=BTOuE5ym; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLSx1-0000wd-8Y; Fri, 27 Jan 2023 12:55:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLSwo-0000oR-Hy for qemu-devel@nongnu.org; Fri, 27 Jan 2023 12:55:35 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLSwl-00060H-I6 for qemu-devel@nongnu.org; Fri, 27 Jan 2023 12:55:34 -0500 Received: by mail-wr1-x435.google.com with SMTP id n7so5684227wrx.5 for ; Fri, 27 Jan 2023 09:55:16 -0800 (PST) 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:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HS55RKKRetN93F2NWMHY8F2JBNqkHa0rbeTZy521S+g=; b=BTOuE5ymc0YAs+KZoRVcBd/LbrCUuuEo+CfbbyCQLmjBDwmdsvbXaozOjKANPmuKjd hbB4HodnootEI+bVM6eeXv/Em95QTEQzjd1lP8ttwbqm1QJw5Hu4F14ouxIJgH+w28AD 1YodUnOEk3zPIxc2JCfmWD7YT1TB0MiUFhJFpvXNFxQdx7cHRBgEC3dm9rY3iOKhvP4P ILyaDWk1yVQ1jMAMXlvXhtjO6pYDQFlLCC4HMMoZZdDngqavJsZ21gQrihsXDc3Hutcv IuY7soSc6ra1XgO47PTFxemidmS5PFJSrAh7xNENXSw5wUcqWxXTIjj35JoqUuPlxVVT mQsw== 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HS55RKKRetN93F2NWMHY8F2JBNqkHa0rbeTZy521S+g=; b=65Ko+6QACns96EqiK95N8eU4xBVfJQOmV2aBOwZuefsiA3CpI0Ww+3nooeIwFWosZq yAfrcQepxJzNlD+zytqOi0hXK3WoKZpNVvGXx0/77QsrmQ51q1g95Dq4g4C62mDovRPp P4/d3+gkHBlHkK9I/BjqGOlfzngMwLW7yADGeMxAMff/07kjF976PO6VaUebfDq8vtDa 31CPBQwZyAUV60aPupIaPNOU/BKzxmI6AONQNtMgo8FjxPNIc7yUNDjA60Pz6NJKZUPh mEVhjdmRXwLPwzek+mz1XZluK8RO6fC6oRCQQJ9hwkbmJlKW+cJQEVnIRn5Gs8X29Bgf mwNg== X-Gm-Message-State: AO0yUKUjfQvwt9MTV8oKeRvK1fAo8JYK4Yn95c1xjIsqty9acJGbzPsN ++VM+Q49PHxowv3usfW5Yr62eA== X-Received: by 2002:a5d:45c6:0:b0:2bf:bfb7:2fde with SMTP id b6-20020a5d45c6000000b002bfbfb72fdemr8366586wrs.30.1674842115757; Fri, 27 Jan 2023 09:55:15 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l13-20020adff48d000000b002366e3f1497sm4545089wro.6.2023.01.27.09.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 09:55:15 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 05/23] target/arm: All UNDEF-at-EL0 traps take priority over HSTR_EL2 traps Date: Fri, 27 Jan 2023 17:54:49 +0000 Message-Id: <20230127175507.2895013-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127175507.2895013-1-peter.maydell@linaro.org> References: <20230127175507.2895013-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x435.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-bounces+patch=linaro.org@nongnu.org The HSTR_EL2 register has a collection of trap bits which allow trapping to EL2 for AArch32 EL0 or EL1 accesses to coprocessor registers. The specification of these bits is that when the bit is set we should trap * EL1 accesses * EL0 accesses, if the access is not UNDEFINED when the trap bit is 0 In other words, all UNDEF traps from EL0 to EL1 take precedence over the HSTR_EL2 trap to EL2. (Since this is all AArch32, the only kind of trap-to-EL1 is the UNDEF.) Our implementation doesn't quite get this right -- we check for traps in the order: * no such register * ARMCPRegInfo::access bits * HSTR_EL2 trap bits * ARMCPRegInfo::accessfn So UNDEFs that happen because of the access bits or because the register doesn't exist at all correctly take priority over the HSTR_EL2 trap, but where a register can UNDEF at EL0 because of the accessfn we are incorrectly always taking the HSTR_EL2 trap. There aren't many of these, but one example is the PMCR; if you look at the access pseudocode for this register you can see that UNDEFs taken because of the value of PMUSERENR.EN are checked before the HSTR_EL2 bit. Rearrange helper_access_check_cp_reg() so that we always call the accessfn, and use its return value if it indicates that the access traps to EL0 rather than continuing to do the HSTR_EL2 check. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/op_helper.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index def5d3515e2..660dae696dd 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -640,10 +640,24 @@ const void *HELPER(access_check_cp_reg)(CPUARMState *env, uint32_t key, goto fail; } + if (ri->accessfn) { + res = ri->accessfn(env, ri, isread); + } + /* - * Check for an EL2 trap due to HSTR_EL2. We expect EL0 accesses - * to sysregs non accessible at EL0 to have UNDEF-ed already. + * If the access function indicates a trap from EL0 to EL1 then + * that always takes priority over the HSTR_EL2 trap. (If it indicates + * a trap to EL3, then the HSTR_EL2 trap takes priority; if it indicates + * a trap to EL2, then the syndrome is the same either way so we don't + * care whether technically the architecture says that HSTR_EL2 trap or + * the other trap takes priority. So we take the "check HSTR_EL2" path + * for all of those cases.) */ + if (res != CP_ACCESS_OK && ((res & CP_ACCESS_EL_MASK) == 0) && + arm_current_el(env) == 0) { + goto fail; + } + if (!is_a64(env) && arm_current_el(env) < 2 && ri->cp == 15 && (arm_hcr_el2_eff(env) & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE)) { uint32_t mask = 1 << ri->crn; @@ -661,9 +675,6 @@ const void *HELPER(access_check_cp_reg)(CPUARMState *env, uint32_t key, } } - if (ri->accessfn) { - res = ri->accessfn(env, ri, isread); - } if (likely(res == CP_ACCESS_OK)) { return ri; }