From patchwork Mon Oct 10 14:27:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 613736 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2016118pvb; Mon, 10 Oct 2022 07:37:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4bkrQC7lYO4cS+K2fPuRFexGScYI3Tto7KhFBhoS6xgi9iEEuuisCaQ7F9Z+xDU2NyLPbh X-Received: by 2002:a05:6214:ace:b0:4b1:af67:e2cb with SMTP id g14-20020a0562140ace00b004b1af67e2cbmr14798238qvi.32.1665412655308; Mon, 10 Oct 2022 07:37:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665412655; cv=none; d=google.com; s=arc-20160816; b=uws6e6CuCTjm2YkmmeLWT7J6auEfyFLaf6nKTzyw+MGnRqYo6SiKiNfAUO+4KgBRfX 2LX5r2mpgrGzAKd+XrWpyATzOMBgR3zxcwU2/sycw6NipbS8R4nPbYCnxOY69MCzqa70 pnINoPbXjyDMpVJlS1NpjwG1fiRh6fCu/yLqHxjrEDLpkY6Og0SgAnFa73ZBifkoJs4C hPT+mJBxUyhkPeG7q/fciqPvTcdCPPq33rpVqCyq70wS15pGgm5TcqHUrq7NTsWe6IB9 PKJiACkbnDeyZHHnx4fMVYCBDBRQSLK+q7h2mGV0A6UVHB/91UprEvTVRf1Bj6HmxYK1 P9PQ== 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=chejyLWzKm+amytX5VjNlCtg/brdV5o/nVcOeHFnjvk=; b=b6hwZVM0K/PMXxOhmq0+mluPoDhDkyh/yi4nMTN1KL3poEeOG4MlCE68zPJw8J2o8M Iz4z2tp+7ODtz6HImPyHqSfd6vFxLucPNi483yx0KqEh9dABAnqP7qgTsK0ZPixh62T8 ZY527OCs4V1AGAtJQUzKrvFpR0v/miWointJBEHqrFKCJzzEoCBuaXr6Chj3y/PSm0Yg jrzyvYA7XMbO98JyN+Fls2ngOB+7MhdRKR3M6h4U6HqItCvlY43IphipnKucVQES6fyZ utbdFju6JOAeQjmkwsllU0tMNQLoo6/DcY4yHk+04vd7r384tVncycML6e0m7vWS0z7c LI9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mbrsbOmU; 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 h17-20020ac87d51000000b00340bca2089bsi6347297qtb.543.2022.10.10.07.37.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 07:37: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=mbrsbOmU; 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]:53458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohtuQ-000739-RP for patch@linaro.org; Mon, 10 Oct 2022 10:37:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohtkv-00069W-2h for qemu-devel@nongnu.org; Mon, 10 Oct 2022 10:27:45 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:40833) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohtks-0005Yk-U4 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 10:27:44 -0400 Received: by mail-wr1-x435.google.com with SMTP id w18so17308806wro.7 for ; Mon, 10 Oct 2022 07:27:42 -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=chejyLWzKm+amytX5VjNlCtg/brdV5o/nVcOeHFnjvk=; b=mbrsbOmU9SkjUpXqqV/47K5N+87SfreWUQFMApH8wqsU5KcYXe09NuXatd4CXZlnTD LJGEALqAFAZcroWcDHXvthPxmDQS8cYkX8U+pXYYe+ZecyT9gG2QdJGpcRSFXpfmKBSm Qny6hwCAGiUhYVCf30qnPXZ5uBdXDAaO1/pM2uWrj49dROSLqeMiHWPIfFmVqq9FhmaV F10osci7CXK0u87QrZjEvknSX3v2ZGdR1x4e+cEPMJTFN17YMH5+ZNoHD/4TkYJP/2MW riGbOJigljRqJ6zQ1uUBWzNqTw5rFVUlTwwNf1RVd0k734wlGHNfNWvWeptyuAA6juVn jFmA== 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=chejyLWzKm+amytX5VjNlCtg/brdV5o/nVcOeHFnjvk=; b=bUr/HDBywjsn9q8IdBKSK0PNhUqdhSXOBheeP4c+yhFddFQk7Mn8Txz0fXf+i38iVD a6nw2KrNl2w1HNOZ8Dv/P330934X9Q6JMhkDub8szcJ3OetMeDm4yPzqsWUBKsXuYf7x odD/PVbt8LBesBSti2UUFpKfVkkLkRvzU6iNeqLm7Z1rNMzeN9DB5C8At3NknwleXfF+ +VVtf10uIowf8u1h/67YyFgt4+odZsQDP/IyamNnb+a8psgYxZhfTHiiz2sIxo3mGbhR JuCaCSPBUj+/1sbmlebL2S0pug2l1ODSyju+KgC7fkF/6LsDIhCf//m8ufdVpHRj4URy TRIQ== X-Gm-Message-State: ACrzQf0aaXLkKUexTll3vMYAMri6MaF1m2yqGEL85CDxHkPlMBNbVcJr 2bqvcLJLaKrr1XahkWTN6963xbau2wodVA== X-Received: by 2002:adf:f407:0:b0:22e:5848:f6b with SMTP id g7-20020adff407000000b0022e58480f6bmr11586883wro.46.1665412061217; Mon, 10 Oct 2022 07:27:41 -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.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 07:27:40 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 08/28] target/arm: Add is_secure parameter to regime_translation_disabled Date: Mon, 10 Oct 2022 15:27:10 +0100 Message-Id: <20221010142730.502083-9-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::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=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 Remove the use of regime_is_secure from regime_translation_disabled, using the new parameter instead. This fixes a bug in S1_ptw_translate and get_phys_addr where we had passed ARMMMUIdx_Stage2 and not ARMMMUIdx_Stage2_S to determine if Stage2 is disabled, affecting FEAT_SEL2. Reviewed-by: Peter Maydell Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson Message-id: 20221001162318.153420-5-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/ptw.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 631d1e25f15..d789807b086 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -131,12 +131,13 @@ static uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn) } /* Return true if the specified stage of address translation is disabled */ -static bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx) +static bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx, + bool is_secure) { uint64_t hcr_el2; if (arm_feature(env, ARM_FEATURE_M)) { - switch (env->v7m.mpu_ctrl[regime_is_secure(env, mmu_idx)] & + switch (env->v7m.mpu_ctrl[is_secure] & (R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK)) { case R_V7M_MPU_CTRL_ENABLE_MASK: /* Enabled, but not for HardFault and NMI */ @@ -163,7 +164,7 @@ static bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx) if (hcr_el2 & HCR_TGE) { /* TGE means that NS EL0/1 act as if SCTLR_EL1.M is zero */ - if (!regime_is_secure(env, mmu_idx) && regime_el(env, mmu_idx) == 1) { + if (!is_secure && regime_el(env, mmu_idx) == 1) { return true; } } @@ -203,7 +204,7 @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, ARMMMUIdx s2_mmu_idx = *is_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; if (arm_mmu_idx_is_stage1_of_2(mmu_idx) && - !regime_translation_disabled(env, s2_mmu_idx)) { + !regime_translation_disabled(env, s2_mmu_idx, *is_secure)) { GetPhysAddrResult s2 = {}; int ret; @@ -1357,7 +1358,7 @@ static bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, uint32_t base; bool is_user = regime_is_user(env, mmu_idx); - if (regime_translation_disabled(env, mmu_idx)) { + if (regime_translation_disabled(env, mmu_idx, is_secure)) { /* MPU disabled. */ result->phys = address; result->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; @@ -1521,7 +1522,7 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, result->page_size = TARGET_PAGE_SIZE; result->prot = 0; - if (regime_translation_disabled(env, mmu_idx) || + if (regime_translation_disabled(env, mmu_idx, secure) || m_is_ppb_region(env, address)) { /* * MPU disabled or M profile PPB access: use default memory map. @@ -1733,7 +1734,7 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address, * are done in arm_v7m_load_vector(), which always does a direct * read using address_space_ldl(), rather than going via this function. */ - if (regime_translation_disabled(env, mmu_idx)) { /* MPU disabled */ + if (regime_translation_disabled(env, mmu_idx, secure)) { /* MPU disabled */ hit = true; } else if (m_is_ppb_region(env, address)) { hit = true; @@ -2307,7 +2308,8 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, result, fi); /* If S1 fails or S2 is disabled, return early. */ - if (ret || regime_translation_disabled(env, ARMMMUIdx_Stage2)) { + if (ret || regime_translation_disabled(env, ARMMMUIdx_Stage2, + is_secure)) { return ret; } @@ -2437,7 +2439,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, /* Definitely a real MMU, not an MPU */ - if (regime_translation_disabled(env, mmu_idx)) { + if (regime_translation_disabled(env, mmu_idx, is_secure)) { uint64_t hcr; uint8_t memattr;