From patchwork Mon Oct 10 14:27:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 613737 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2016611pvb; Mon, 10 Oct 2022 07:38:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM62tTd4jlfhas3YWvpfZ46W0gIFWVrR5Kzct+x5sjYST4x3IwhJH7kq/0hy8638kwwDc79A X-Received: by 2002:ac8:5983:0:b0:35c:c560:a3f8 with SMTP id e3-20020ac85983000000b0035cc560a3f8mr14723305qte.600.1665412706903; Mon, 10 Oct 2022 07:38:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665412706; cv=none; d=google.com; s=arc-20160816; b=tUCKFJl9emijE1/VEq/ccYrkH9a/9dKcZIY8UAHk5UATyMU/T3yEF/nsW5ZJimoHGQ l8yOUlj3evVUV26LxCIp9xvj3glBKQ/NHOOKWB3Fcmyn78LT4ICblVMyj+4rWK1lIQeO 0MlOc8MPqs4JFOlbAMKFJmkH0Z1jzillEcwIxaawsUNnO7I4MNSUyWDjM4vlQHcKu53j kioOhoVDVInBGU12L4AG/otpwoAINb0HoOPI9kM8DGrUdC9C+wICwI9ISG1lMcXu+9Tb rtIMEd0+Zr2zYLVb4CRJtl0Gc6L361/iPVzGYN8bn7wxHPqRrHvMd8Ra3gnbR4OmXfGE 7tBA== 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=B/NSK08PHYfCbr/Iig3swg/Ik7nPMnQ9pNlEcYvtrnQ=; b=EIcw02636Id5uhDoDsWWF85EXvsf3v6Lex+OWAQxxgD3a0ocNIFBQHIxbAVFsemt3d k9XiOq8kWrf6wf2dv+EMt4gYgeyanGDFBEOk5FgAxDRRCv+R/78pw80luKXD5l2y+Yft GHQZUxm40km3DtxXXvm6TNwPJBdi8B3kZZ15gobnGCpme2qlftdc+oEQ1VLsrGv4vzAB bQD6mFhMSsYRq5vbSr4spM1sQaYnzEFMBokScD8367bOiWns5Rn/bAqKbEuFIySyKDaP vW0RGeRLTBShgi3s7+ba7IBdA2kFr/2Dmyn9sm/0trTgJd4FHIkN0U1n9fbP5s+/I0cs QirA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kM8guZuh; 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 i18-20020a05620a405200b006ced43908ccsi6246370qko.669.2022.10.10.07.38.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 07:38:26 -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=kM8guZuh; 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]:53856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohtvG-0000dr-CQ for patch@linaro.org; Mon, 10 Oct 2022 10:38:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohtl7-0006Rc-Ee for qemu-devel@nongnu.org; Mon, 10 Oct 2022 10:27:57 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:45721) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohtl4-0005b0-VK for qemu-devel@nongnu.org; Mon, 10 Oct 2022 10:27:57 -0400 Received: by mail-wr1-x42c.google.com with SMTP id a10so17266986wrm.12 for ; Mon, 10 Oct 2022 07:27:54 -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:to:from:from:to:cc:subject:date:message-id :reply-to; bh=B/NSK08PHYfCbr/Iig3swg/Ik7nPMnQ9pNlEcYvtrnQ=; b=kM8guZuhlYewVHNy5wPXIy1fgQ4hLpND7GoPe36jKjL+s4qcx0HSCWpbMGnED28led L09U9kp82/5KhWw2XLsKqRxXEWIk4IXkaa4IOpFCJS9DxTyTuLnS2L/ncnrHisUxe4oT 8sncrB5ttyGAIIrY2DzvYmXmCBUJdJ0G2GPYsP+ZUw/C8SUop4Y6yxxcj0hWXMPMFK4J kyp7anT+R6rm7Tw0CfjFKtfG21aehSXqrW/y3hk/2eiQmhxYt5f6bFq9uF4vWPM+d1XW eJcVQGApurCqXq9n8jWgWoV0h4F74JB3hPbumHsHOFtJ8wRkZeVkBQdf8iT19XOvgOda xaxg== 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=B/NSK08PHYfCbr/Iig3swg/Ik7nPMnQ9pNlEcYvtrnQ=; b=Dr7FcTvk7NomEo9D5iLCGcOGXTaanUsjL1/fJeyD5f+6S3Q6tONVjgd8QxLvm1IH25 GeYIKN57p6evQEv+JUNbpNxqpxWPh+sv1KTIxl2kztT1Uu2EIo462NFfsanX4OhNFrtA pmF+N2Zypr5AHrly5UM1D/maOHJ6lYtrh4lwcfEQCpLjVcm2n/biZeavQFqe7izXLjR5 xALbmdqtu+GtFFgbj571KxsIu+PlesgnLZIATImKgdS2xO9e6oKVfd4mAWSgylldoYIc 1ZqQWY2/DTe0vnrtJal8Kh6DrHvkgELfhWFl8/Awb+QaZtAStYImsxVmP4dnNSNu/LKh kFJg== X-Gm-Message-State: ACrzQf3JwkePjiunIgj408STWagGEc20EL9SVhZ1JvUFIVNc6yQZyMJB llHXA/OOdNf80OpP4XnPuWEc6fneX7ApSg== X-Received: by 2002:a5d:6d8a:0:b0:22f:1ade:de87 with SMTP id l10-20020a5d6d8a000000b0022f1adede87mr8645580wrs.3.1665412073459; Mon, 10 Oct 2022 07:27:53 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u6-20020adfed46000000b0022e04bfa661sm9037054wro.59.2022.10.10.07.27.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 07:27:52 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 20/28] target/arm: Pass HCR to attribute subroutines. Date: Mon, 10 Oct 2022 15:27:22 +0100 Message-Id: <20221010142730.502083-21-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221010142730.502083-1-peter.maydell@linaro.org> References: <20221010142730.502083-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.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=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" From: Richard Henderson 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. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-id: 20221001162318.153420-17-richard.henderson@linaro.org Signed-off-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 7d607c2e7b5..b4fd4d3fac1 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. @@ -2059,14 +2061,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 */ @@ -2112,12 +2114,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); @@ -2217,7 +2219,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; @@ -2244,10 +2246,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); } /* @@ -2290,6 +2292,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); @@ -2338,7 +2341,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, @@ -2351,7 +2355,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); /*