From patchwork Sun Jul 3 08:23:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 586836 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp2931409mab; Sun, 3 Jul 2022 02:10:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1skeybZ5I23sY6mzcZVbO25FKhQQarS2y5m/0oQeMUMjKZVZcHQzCjwrecSxz39qW5MkOvU X-Received: by 2002:a5b:191:0:b0:66e:1afe:ae02 with SMTP id r17-20020a5b0191000000b0066e1afeae02mr8127054ybl.310.1656839435552; Sun, 03 Jul 2022 02:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656839435; cv=none; d=google.com; s=arc-20160816; b=pvhr8+mMFNesR4JcsDta2OKjQIzuvvlyo15pgHPKha2cchbRcYP3DKCi7CRJepiH+0 6JjWgix1EP8E+Kkg/tIUqBXPwtal8t6zsFF7XZssnnvDTrBWuuMgcEeAAMmlzaKsccwH QSDECWFesDXu3+BG4C76vlO0sqnhF9MxphOVzseFcirxBOUHGym7n1zsfHFj8qjn/ib1 hx1ee4j/90FbJBMMCKveu4Gf7zmZwXLCMnAxoQo+zZZyhkU6Gh+oWm/igz2NXo7kAqHE GA4J6gPitGD3adjPqoc3nde7Q1xzsUfNEl4M95qqXopF7j02HwoDInBWeKqtMbEfJNDS 2CSw== 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=27Wz5DSCW8ENXu7065ZoRBnr2V/wpxEQdmpGVTXjexE=; b=yXopMoaoTROf4ubh7AkVnz9k1GpPJqEdOBi88cL/Xrj+9AKb/N7mTPMbJ6FZW9+15I YgY+SevZmOHVEIYs63oD8NeyLQsYRazNInmAmMVTdqqkUk+jMhlX0qHXTXAiNJlZG1h2 nbxZiKG0iNj71DqDmITR05oFFNwSwQfvAyuT6fk3UnISGJUzny7kgmVaSytNTOjrXwKj G3haEeyCK4vamJrWpGm9MeSj9wq+CPEKk8RUjwzfXnksle0pS37fMMjHyti3DhZKlT+D NFRIVjMIlLoJjJVKYxyIKDx7YdAJ/AKPAQ5nTuI4WD/ZSrSf92EkLM0UE/68PWp1IqY+ ECzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xu9jo53r; 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 83-20020a251856000000b00668d1918bb9si31037799yby.423.2022.07.03.02.10.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 Jul 2022 02:10:35 -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=Xu9jo53r; 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]:51716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7vcg-0004Jd-UA for patch@linaro.org; Sun, 03 Jul 2022 05:10:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7uz0-0007zZ-B9 for qemu-devel@nongnu.org; Sun, 03 Jul 2022 04:29:34 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:42498) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o7uyy-0006eZ-IN for qemu-devel@nongnu.org; Sun, 03 Jul 2022 04:29:34 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 73-20020a17090a0fcf00b001eaee69f600so6730402pjz.1 for ; Sun, 03 Jul 2022 01:29:32 -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=27Wz5DSCW8ENXu7065ZoRBnr2V/wpxEQdmpGVTXjexE=; b=Xu9jo53rFlJ5Dh9QjQrdUNB4WTXW4vg8+1m2VgkVZW/YcSpGmTbvNArlRlVqniHUWf fWV/Is4uoz2xBBWB/J+k7mVXneuqo2t/ss8fYS4j6AdjSy/miy1CG6XTuScaYncPD1Le qag4k9osKMzhcF0E4p7i/7JhWfjgaRo8ePEiV2MbbpSgR2jUWNz3N27pwr2jtQSOzOMz 0wQDlJ3G6fDguWsETHVFy/XRqJMmFZYPAxIgSXfg2+4saCQA6edpozimCOOUG9bdWw5b PolXg2NbstWN+C2ayLOGBpvgABBFZcCPl4Z3EFGBpHN0E/5TcnHQ/Qy9aimOm6V3kSmS ZXcA== 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=27Wz5DSCW8ENXu7065ZoRBnr2V/wpxEQdmpGVTXjexE=; b=K0M7ACqa2DkzAJaUY/vv1WseDjCQonZ7PhJRN5Jp/OfZcl9Wk768LTmdQALtBhR2GZ b3ItCPUoxuFvTF7HSBUIWMMT/yLcNuvJn2W9f2CVRQt4SMf+7SMAWCX9jzyHYxo1TJX+ oXT1APcKN5QF9OeXJPaOWV2gR9qITRFsZbC6/9BVWSiuGr5uLwnaJ1TNSBqphzUgHmia hJz2Q7B2P9Eu5E88R+1ckWOanpo5CUbLgoLf2+t2IKj9pD1zVvzX5OhsFKb8xjjdLskR 9xtuA+hvYzrjDk2aw6rEQtkeebpoYHxHvH0+34Ac+tlSEHozNPuqMKi69dK7gyu4VR9P 7c0g== X-Gm-Message-State: AJIora8S16G4ZH3+qpVSbLC+tmegOpToRb3OPnulVM968FDiN+9RI5Ij FKXWJ5DjKTXgfgmb9IKWvKKa8sXcZ+9EG4cM X-Received: by 2002:a17:90b:4d84:b0:1ec:aa85:b8ea with SMTP id oj4-20020a17090b4d8400b001ecaa85b8eamr27145064pjb.194.1656836971216; Sun, 03 Jul 2022 01:29:31 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id g6-20020a1709026b4600b0016788487357sm18574523plt.132.2022.07.03.01.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jul 2022 01:29:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 40/62] target/arm: Pass HCR to attribute subroutines. Date: Sun, 3 Jul 2022 13:53:57 +0530 Message-Id: <20220703082419.770989-41-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220703082419.770989-1-richard.henderson@linaro.org> References: <20220703082419.770989-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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=ham 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" These subroutines did not need ENV for anything except retrieving the effective value of HCR anyway. We have computed the effective value of HCR in the callers, and this will be especially important for interpreting HCR in a non-current security state. Signed-off-by: Richard Henderson --- target/arm/ptw.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 93c533e60d..a760ab86c5 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -186,7 +186,7 @@ static bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx, return (regime_sctlr(env, mmu_idx) & SCTLR_M) == 0; } -static bool ptw_attrs_are_device(CPUARMState *env, ARMCacheAttrs cacheattrs) +static bool ptw_attrs_are_device(uint64_t hcr, ARMCacheAttrs cacheattrs) { /* * For an S1 page table walk, the stage 1 attributes are always @@ -198,7 +198,7 @@ static bool ptw_attrs_are_device(CPUARMState *env, ARMCacheAttrs cacheattrs) * when cacheattrs.attrs bit [2] is 0. */ assert(cacheattrs.is_s2_format); - if (arm_hcr_el2_eff(env) & HCR_FWB) { + if (hcr & HCR_FWB) { return (cacheattrs.attrs & 0x4) == 0; } else { return (cacheattrs.attrs & 0xc) == 0; @@ -216,6 +216,7 @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, if (arm_mmu_idx_is_stage1_of_2(mmu_idx) && !regime_translation_disabled(env, s2_mmu_idx, is_secure)) { GetPhysAddrResult s2 = {}; + uint64_t hcr; int ret; ret = get_phys_addr_lpae(env, addr, MMU_DATA_LOAD, s2_mmu_idx, @@ -228,8 +229,9 @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, fi->s1ns = !is_secure; return ~0; } - if ((arm_hcr_el2_eff(env) & HCR_PTW) && - ptw_attrs_are_device(env, s2.cacheattrs)) { + + hcr = arm_hcr_el2_eff(env); + if ((hcr & HCR_PTW) && ptw_attrs_are_device(hcr, s2.cacheattrs)) { /* * PTW set and S1 walk touched S2 Device memory: * generate Permission fault. @@ -2055,14 +2057,14 @@ static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, * ref: shared/translation/attrs/S2AttrDecode() * .../S2ConvertAttrsHints() */ -static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs) +static uint8_t convert_stage2_attrs(uint64_t hcr, uint8_t s2attrs) { uint8_t hiattr = extract32(s2attrs, 2, 2); uint8_t loattr = extract32(s2attrs, 0, 2); uint8_t hihint = 0, lohint = 0; if (hiattr != 0) { /* normal memory */ - if (arm_hcr_el2_eff(env) & HCR_CD) { /* cache disabled */ + if (hcr & HCR_CD) { /* cache disabled */ hiattr = loattr = 1; /* non-cacheable */ } else { if (hiattr != 1) { /* Write-through or write-back */ @@ -2108,12 +2110,12 @@ static uint8_t combine_cacheattr_nibble(uint8_t s1, uint8_t s2) * s1 and s2 for the HCR_EL2.FWB == 0 case, returning the * combined attributes in MAIR_EL1 format. */ -static uint8_t combined_attrs_nofwb(CPUARMState *env, +static uint8_t combined_attrs_nofwb(uint64_t hcr, ARMCacheAttrs s1, ARMCacheAttrs s2) { uint8_t s1lo, s2lo, s1hi, s2hi, s2_mair_attrs, ret_attrs; - s2_mair_attrs = convert_stage2_attrs(env, s2.attrs); + s2_mair_attrs = convert_stage2_attrs(hcr, s2.attrs); s1lo = extract32(s1.attrs, 0, 4); s2lo = extract32(s2_mair_attrs, 0, 4); @@ -2213,7 +2215,7 @@ static uint8_t combined_attrs_fwb(ARMCacheAttrs s1, ARMCacheAttrs s2) * @s1: Attributes from stage 1 walk * @s2: Attributes from stage 2 walk */ -static ARMCacheAttrs combine_cacheattrs(CPUARMState *env, +static ARMCacheAttrs combine_cacheattrs(uint64_t hcr, ARMCacheAttrs s1, ARMCacheAttrs s2) { ARMCacheAttrs ret; @@ -2240,10 +2242,10 @@ static ARMCacheAttrs combine_cacheattrs(CPUARMState *env, } /* Combine memory type and cacheability attributes */ - if (arm_hcr_el2_eff(env) & HCR_FWB) { + if (hcr & HCR_FWB) { ret.attrs = combined_attrs_fwb(s1, s2); } else { - ret.attrs = combined_attrs_nofwb(env, s1, s2); + ret.attrs = combined_attrs_nofwb(hcr, s1, s2); } /* @@ -2309,6 +2311,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, ARMCacheAttrs cacheattrs1; ARMMMUIdx s2_mmu_idx; bool is_el0; + uint64_t hcr; ret = get_phys_addr_with_secure(env, address, access_type, s1_mmu_idx, is_secure, result, fi); @@ -2354,7 +2357,8 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, } /* Combine the S1 and S2 cache attributes. */ - if (arm_hcr_el2_eff(env) & HCR_DC) { + hcr = arm_hcr_el2_eff(env); + if (hcr & HCR_DC) { /* * HCR.DC forces the first stage attributes to * Normal Non-Shareable, @@ -2367,7 +2371,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, } cacheattrs1.shareability = 0; } - result->cacheattrs = combine_cacheattrs(env, cacheattrs1, + result->cacheattrs = combine_cacheattrs(hcr, cacheattrs1, result->cacheattrs); /* Check if IPA translates to secure or non-secure PA space. */