From patchwork Mon Aug 22 15:27:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 599170 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp1839100mae; Mon, 22 Aug 2022 10:31:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR6fgAXmnr1qjCTNKDj6yb1ykf8PS+IikP0HhippkqDwTqvqUurnhWrbE8Pb6O8eVRvad+9f X-Received: by 2002:a05:620a:d82:b0:6a9:9102:3948 with SMTP id q2-20020a05620a0d8200b006a991023948mr12966572qkl.56.1661189496957; Mon, 22 Aug 2022 10:31:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661189496; cv=none; d=google.com; s=arc-20160816; b=iXz5+tBmCAvTUhljILSY/lSMYvXWlBfvG+q12Ns2R8yKx1WYXo0pP3KJa+XrjUZNZp JMcQUUO3lfypVN8UZZ6oPL3z5s0Cu7EZzRTrvFyu2BTkQVmS5cKuQgDINXuZ1vyVE0xm q5XyTbi0CL1X/p/LKJZZjWUgW+lH17K6RQgYX31Fnzjrly1Z+Wy5XSa8Vt+V+3MeTsV9 6BaEvszyC5GF9p2gj7CTViNupXC2yXOTRsTPccR9oPJw6Fla7hZPcms3DL4DwQOCsrkb AAtypeARVC946NpPBqL947WvyR82vg0HYqmn7DGG6mlvu59qE2+vStRk2RGM9XXuiD6P HvOg== 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=d/aaxeEB38f4APqu+4DPv/6ce6klQuxkyZkiEyQwHcw=; b=wrWxwb/Mze3Nqpe5RGd3SAJea5MqXip3kiM3DZIp7rbTWmE0BvBTYOSuRXSmCt1Iwb T9fyZKqSSxngX8X43FsRmyEM2C2t0RT3GajT+SYC3X3Ieb9sGjng0TiO30e9x/rLde60 EBNC98ivtWqeK0BVj1UdppcTQsvI+XFd8EyJcK5FkrSQVGkJLwdM+NUnl/lLO2QAX7Fq k3EUPrxq+GNL7KjfIJE4RCNSGS0mufqhkAqmlev62evcUoPeEhWRjoWwoHrPbYfz0WsS 9QuYVX2bAxbjOmihzxPlW4ve2uJlKuyIV/R6QvlF25fWlPUtPz5SW5IThTAG59t/MrPv /1Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KMfIAwLm; 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 o13-20020a05620a2a0d00b006af090bac19si5180597qkp.722.2022.08.22.10.31.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Aug 2022 10:31:36 -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=KMfIAwLm; 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]:58088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQBGv-0000jS-Ow for patch@linaro.org; Mon, 22 Aug 2022 13:31:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ9Lp-0000Pu-Mj for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:28:29 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:33436) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ9LY-0000dc-Mx for qemu-devel@nongnu.org; Mon, 22 Aug 2022 11:28:29 -0400 Received: by mail-pl1-x631.google.com with SMTP id 2so10269305pll.0 for ; Mon, 22 Aug 2022 08:28:12 -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; bh=d/aaxeEB38f4APqu+4DPv/6ce6klQuxkyZkiEyQwHcw=; b=KMfIAwLmby1RwdnpRd2TFkkaVbj1UsXWn3nbpOCSHFZcry1KYVrCGC0+HmPUmU4gtK 7P1u7lzBA3fSJh9C4mGlTdgPmWnnV3RXW/p06t8uiMULyvH6bZkxLDUPNP6YdWzoq0gu 3QvYsH4b0uyjC5wRXICglzw0HPqHpLaiZKk0aARTr9ZIXQ/MUvzVpOVgTdxOVPykZjwZ 7U77+/5EQZWZbW7Ao9Q/cx4yCPW//XEsJ9IHOd4MFyQ5Y6DMUDZoM6A5T/Qa7Fr1WmCo XPnk1q9FnVSKHEnVlJMIFEgBZttyf37JCCArrvpJPSgLlhIal80nuvAKTXeBzxK45eio xqqQ== 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; bh=d/aaxeEB38f4APqu+4DPv/6ce6klQuxkyZkiEyQwHcw=; b=xZGQJh8StA/mG2yuFyeSHAdOFrhlevhxWGZ8jYRV0dL3xLJIsGRHhAkpROVICd3ym9 lhQ28a10e9PSksR4y2WNL12Bv4fTrVrj8HpeK/JHVZGwiDrhL9F8wGpj76WYX8OOvMj9 wCd6sAFeewLSG8F8kQ+PFoVp3VAr6gu4np5EPDB/KcpDMTzszgU0sF51si7zQfrxRi7L 0tRvkng5lty+W/AUWxsKO277rSsceQJIWDry6EIj9GqDPgDzfoTUkDX5sNLq+CJFUSFl 2wDZwdghkWYqR5j+auS9Z79maQP/WmCtuxtLVDthRbBzXw8xkM4XxX18fH8CxgrAS0tD 857g== X-Gm-Message-State: ACgBeo3WA2NuFaAHy57h2L2Bvd7cwKXnhqx/a+XrN9DtYi+EnfrNPhbf Ad6G5ip43WNfTL+X9FVCaSEA3eO2/dqMLg== X-Received: by 2002:a17:90b:4b8d:b0:1fb:4def:1fc1 with SMTP id lr13-20020a17090b4b8d00b001fb4def1fc1mr2471775pjb.121.1661182091764; Mon, 22 Aug 2022 08:28:11 -0700 (PDT) Received: from stoup.. ([71.212.157.236]) by smtp.gmail.com with ESMTPSA id q7-20020a17090311c700b0016bffc59718sm8665222plh.58.2022.08.22.08.28.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 08:28:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 33/66] target/arm: Pass HCR to attribute subroutines. Date: Mon, 22 Aug 2022 08:27:08 -0700 Message-Id: <20220822152741.1617527-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822152741.1617527-1-richard.henderson@linaro.org> References: <20220822152741.1617527-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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" 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 Reviewed-by: Peter Maydell --- 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 5c6e5eea88..fe06bb032b 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. @@ -2058,14 +2060,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 */ @@ -2111,12 +2113,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); @@ -2216,7 +2218,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; @@ -2243,10 +2245,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); } /* @@ -2312,6 +2314,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); @@ -2357,7 +2360,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, @@ -2370,7 +2374,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. */