From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935757; cv=none; d=zohomail.com; s=zohoarc; b=VAiFPibgQsyuZWDZN8AhgeSn8oT0wExs9EeOGvIRzfsN/IJ6qIeHuGOTxDnE+Ypen8d3OyRaB1ctgkfb1As/P64v7DMUreGYgQDD+QEeTL5wxXJZMUnB8r2rafG/5cdteo6eBDytdyWjPtW2lUv1Fyt0VcUCD219aBWwmCkRtYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935757; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Hddjs2iU8lgJmQnwAvhIIZw97YOfc6Ski+WodJ2W4+A=; b=TcKUNSOLhO+0iLtWO/wkPSuz5T03F50Cl/AdumZvUIdRH3Mg0hVq9q2yAD2lwoVP9evUP9Rr+Nse1yInDFk5o7LT01eF12NHtfbsBZVo84GP5XQlBKypvJUp9xNSmEq3TkdqW6OVwN/3ZWdaSzjaaKGOwXIkVrqW7axY1Kv91qw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935757087500.9443297414997; Mon, 20 Feb 2023 15:29:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYO-0003gy-31; Mon, 20 Feb 2023 18:26:40 -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 1pUFYK-0003ek-JI for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:37 -0500 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYI-0000HJ-Dh for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:36 -0500 Received: by mail-pj1-x1042.google.com with SMTP id cp9so3981687pjb.0 for ; Mon, 20 Feb 2023 15:26:34 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:32 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Hddjs2iU8lgJmQnwAvhIIZw97YOfc6Ski+WodJ2W4+A=; b=V3BLRJTX8Qq4f7g5vSdXiAZvyvdi8X3Eg62l3jCCNzKLoJsTlQDsN9wnRdFOAXdBzp 96d8cZibJmYrzOAGpzEgn8AfvjAe9h+M6Z8Ny2JohJr4RR6UqB9uXGOOnqZiwzcgpt6o yOgaV4QDSCTXJwYHvacgXWIrXmoJ8HX4bMQWG/QoTRsbhGcC0b7RSyviT42G6QBrXNk8 B9f0g+7IV85ZxamXJUT7+5cA87MZsWlpFnPlHHfZlmMWmsygIveoei5/D68pw2M8BntV 4lb7NSLEpBdp3t3KNCDlxelZjf8kJ05puNjkr77mF4waqCag2qgm0fVIHzkQGo58Kzmc d/tQ== 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 :subject:date:message-id:reply-to; bh=Hddjs2iU8lgJmQnwAvhIIZw97YOfc6Ski+WodJ2W4+A=; b=5oDe8lFywDuV+Lzp69O6Brm5mi9KTwIxy1w36Cip45TpRNxiX9vevNCnXyShEmr9rR h/MjwmfyB9wbkCTpy3wqLDuSelpcdDA5LgF7NNYTxA3LxZqX6Bwk2iit6+XwpxW3FYyW hb93W1eJ979aA2vxS5mEaK2mA+gDUezmxOLXFv27L413RQQFZStoFHxUtyCJE/C93Fkl HaBWjvPJjtvGGjURNl/FU5M3VttfZ+7g1IBJEHKjbSs+grUPSuyfLfcCSVnzQt6WGeuJ osCHekgNq1coAkgMahDexKtPEhEUugBBgPbpvOD2PoxhJQUgaeSAmD2bG9icycl6zh7Z 9H3Q== X-Gm-Message-State: AO0yUKXuWOJPLjFX++dvklUNIWh2NPSzUA+KQA+30kcejLCrLEM4eD8H +G716dVtF67ua9t8mQ/G2aSfg62rMsynxmZYWDxhzg== X-Google-Smtp-Source: AK7set/kvPnaZ9oPMeGJCfZdHVdUBR+3E9oDcilzpecbQ2DTTVZGVnJB1nPh6hvaTiKWzvNAYVtvAg== X-Received: by 2002:a17:902:e547:b0:19a:abb0:1e with SMTP id n7-20020a170902e54700b0019aabb0001emr4473312plf.38.1676935592731; Mon, 20 Feb 2023 15:26:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 01/21] target/arm: Rewrite check_s2_mmu_setup Date: Mon, 20 Feb 2023 13:26:06 -1000 Message-Id: <20230220232626.429947-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1042; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1042.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935758163100005 Content-Type: text/plain; charset="utf-8" Integrate neighboring code from get_phys_addr_lpae which computed starting level, as it is easier to validate when doing both at the same time. Mirror the checks at the start of AArch{64,32}.S2Walk, especially S2InvalidSL and S2InconsistentSL. This reverts 49ba115bb74, which was incorrect -- there is nothing in the ARM pseudocode that depends on TxSZ, i.e. outputsize; the pseudocode is consistent in referencing PAMax. Fixes: 49ba115bb74 ("target/arm: Pass outputsize down to check_s2_mmu_setup= ") Signed-off-by: Richard Henderson --- target/arm/ptw.c | 173 ++++++++++++++++++++++++++--------------------- 1 file changed, 97 insertions(+), 76 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 2b125fff44..6fb72fb086 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1077,70 +1077,119 @@ static ARMVAParameters aa32_va_parameters(CPUARMSt= ate *env, uint32_t va, * check_s2_mmu_setup * @cpu: ARMCPU * @is_aa64: True if the translation regime is in AArch64 state - * @startlevel: Suggested starting level - * @inputsize: Bitsize of IPAs + * @tcr: VTCR_EL2 or VSTCR_EL2 + * @ds: Effective value of TCR.DS. + * @iasize: Bitsize of IPAs * @stride: Page-table stride (See the ARM ARM) * - * Returns true if the suggested S2 translation parameters are OK and - * false otherwise. + * Decode the starting level of the S2 lookup, returning INT_MIN if + * the configuration is invalid. */ -static bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, - int inputsize, int stride, int outputsize) +static int check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, uint64_t tcr, + bool ds, int iasize, int stride) { - const int grainsize =3D stride + 3; - int startsizecheck; - - /* - * Negative levels are usually not allowed... - * Except for FEAT_LPA2, 4k page table, 52-bit address space, which - * begins with level -1. Note that previous feature tests will have - * eliminated this combination if it is not enabled. - */ - if (level < (inputsize =3D=3D 52 && stride =3D=3D 9 ? -1 : 0)) { - return false; - } - - startsizecheck =3D inputsize - ((3 - level) * stride + grainsize); - if (startsizecheck < 1 || startsizecheck > stride + 4) { - return false; - } + int sl0, sl2, startlevel, granulebits, levels; + int s1_min_iasize, s1_max_iasize; =20 + sl0 =3D extract32(tcr, 6, 2); if (is_aa64) { + /* + * AArch64.S2InvalidTxSZ: While we checked tsz_oob near the top of + * get_phys_addr_lpae, that used aa64_va_parameters which apply + * to aarch64. If Stage1 is aarch32, the min_txsz is larger. + * See AArch64.S2MinTxSZ, where min_tsz is 24, translated to + * inputsize is 64 - 24 =3D 40. + */ + if (iasize < 40 && !arm_el_is_aa64(&cpu->env, 1)) { + goto fail; + } + + /* + * AArch64.S2InvalidSL: Interpretation of SL depends on the page s= ize, + * so interleave AArch64.S2StartLevel. + */ switch (stride) { - case 13: /* 64KB Pages. */ - if (level =3D=3D 0 || (level =3D=3D 1 && outputsize <=3D 42)) { - return false; + case 9: /* 4KB */ + /* SL2 is RES0 unless DS=3D1 & 4KB granule. */ + sl2 =3D extract64(tcr, 33, 1); + if (ds && sl2) { + if (sl0 !=3D 0) { + goto fail; + } + startlevel =3D -1; + } else { + startlevel =3D 2 - sl0; + switch (sl0) { + case 2: + if (arm_pamax(cpu) < 44) { + goto fail; + } + break; + case 3: + if (!cpu_isar_feature(aa64_st, cpu)) { + goto fail; + } + startlevel =3D 3; + break; + } } break; - case 11: /* 16KB Pages. */ - if (level =3D=3D 0 || (level =3D=3D 1 && outputsize <=3D 40)) { - return false; + case 11: /* 16KB */ + switch (sl0) { + case 2: + if (arm_pamax(cpu) < 42) { + goto fail; + } + break; + case 3: + if (!ds) { + goto fail; + } + break; } + startlevel =3D 3 - sl0; break; - case 9: /* 4KB Pages. */ - if (level =3D=3D 0 && outputsize <=3D 42) { - return false; + case 13: /* 64KB */ + switch (sl0) { + case 2: + if (arm_pamax(cpu) < 44) { + goto fail; + } + break; + case 3: + goto fail; } + startlevel =3D 3 - sl0; break; default: g_assert_not_reached(); } - - /* Inputsize checks. */ - if (inputsize > outputsize && - (arm_el_is_aa64(&cpu->env, 1) || inputsize > 40)) { - /* This is CONSTRAINED UNPREDICTABLE and we choose to fault. = */ - return false; - } } else { - /* AArch32 only supports 4KB pages. Assert on that. */ + /* + * Things are simpler for AArch32 EL2, with only 4k pages. + * There is no separate S2InvalidSL function, but AArch32.S2Walk + * begins with walkparms.sl0 in {'1x'}. + */ assert(stride =3D=3D 9); - - if (level =3D=3D 0) { - return false; + if (sl0 >=3D 2) { + goto fail; } + startlevel =3D 2 - sl0; } - return true; + + /* AArch{64,32}.S2InconsistentSL are functionally equivalent. */ + levels =3D 3 - startlevel; + granulebits =3D stride + 3; + + s1_min_iasize =3D levels * stride + granulebits + 1; + s1_max_iasize =3D s1_min_iasize + (stride - 1) + 4; + + if (iasize >=3D s1_min_iasize && iasize <=3D s1_max_iasize) { + return startlevel; + } + + fail: + return INT_MIN; } =20 /** @@ -1296,38 +1345,10 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1= Translate *ptw, */ level =3D 4 - (inputsize - 4) / stride; } else { - /* - * For stage 2 translations the starting level is specified by the - * VTCR_EL2.SL0 field (whose interpretation depends on the page si= ze) - */ - uint32_t sl0 =3D extract32(tcr, 6, 2); - uint32_t sl2 =3D extract64(tcr, 33, 1); - int32_t startlevel; - bool ok; - - /* SL2 is RES0 unless DS=3D1 & 4kb granule. */ - if (param.ds && stride =3D=3D 9 && sl2) { - if (sl0 !=3D 0) { - level =3D 0; - goto do_translation_fault; - } - startlevel =3D -1; - } else if (!aarch64 || stride =3D=3D 9) { - /* AArch32 or 4KB pages */ - startlevel =3D 2 - sl0; - - if (cpu_isar_feature(aa64_st, cpu)) { - startlevel &=3D 3; - } - } else { - /* 16KB or 64KB pages */ - startlevel =3D 3 - sl0; - } - - /* Check that the starting level is valid. */ - ok =3D check_s2_mmu_setup(cpu, aarch64, startlevel, - inputsize, stride, outputsize); - if (!ok) { + int startlevel =3D check_s2_mmu_setup(cpu, aarch64, tcr, param.ds, + inputsize, stride); + if (startlevel =3D=3D INT_MIN) { + level =3D 0; goto do_translation_fault; } level =3D startlevel; --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935744; cv=none; d=zohomail.com; s=zohoarc; b=DgPuvRNtoEHlmP3nKz0K+OHYqKxiNZiwsixB4SpYa8l871cFB/76jlWhVZztnhLMhZquRTsZG8YpgIRuuKSeXgzpr8wWu5tOsdcffIfbZbx2iTCjowtIRdM3WjtCCoyvaR09Erh+aBb1mnIYCYUGs39ZVnc31F2k45Kfq9kL6Ig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935744; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6Qu5gxD3YQ1g3NpmrFTN+XCbNU1pC9zMqzEJSxEiZBE=; b=Dsw9OZ5lE0OZelsY7CV4tom/wsm+RcEJciDMpCT7jYFjPGC0KB6QHjHtEH5HVBdhta1bTYlBt9LtPboBewYiCQBchD5uLwMVQjeSDPHs3gTCS6+PkayjMDewTbtk4VaepHFP9mHwYZyxU1yarjRBjVE6+GJzdJjH2j/DSJEqerA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935744536313.9468914857986; Mon, 20 Feb 2023 15:29:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYO-0003hQ-IO; Mon, 20 Feb 2023 18:26:40 -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 1pUFYL-0003fc-Tu for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:37 -0500 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYK-0000IO-Bs for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:37 -0500 Received: by mail-pj1-x1041.google.com with SMTP id g14so2820759pjb.2 for ; Mon, 20 Feb 2023 15:26:35 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:33 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6Qu5gxD3YQ1g3NpmrFTN+XCbNU1pC9zMqzEJSxEiZBE=; b=EKXdduJeENkKGmYARPZuvL7nQxI2Igm3uWPxBmFsncScgp1LYpRiQvYefGiokIeWv9 VJiqZ2J1057wvZTcK9Wff9gKkILwnI6eoIcSg5rUYys6wGUImYnfCZzm6cvICMT32ogE 8WV6zKCfXKrm/PdPiMw0+ypn9Qi3ZxzFcpSdMO7BcNpgUbij4PMIWxC81tsdp2mVBfIe ARHw83iUwVNO2FXYicNeoR2/X68BDhgBpjuqkQVolv8PIOA9KN+hA9V+maoDh8P9lEO5 iBV3GUhrzGsxDK05drysVBP64AiDCmjGaavFadgxb6o/8NGN0lMyZf0TG+69g0s2S9d6 NCzw== 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 :subject:date:message-id:reply-to; bh=6Qu5gxD3YQ1g3NpmrFTN+XCbNU1pC9zMqzEJSxEiZBE=; b=He+/Q5wzPJ2uetH8xbOXRaURrJFYoxsxOYjBlq506sBdAn3ug3ck/Lr6ZKKdFuBr8S 8YzO7+ad35CwL2DTwImApMrdJztiMqgmpDRFOJ2RYP1fyTxNurG0tZDzA6YJ5QhTUZJl rrKcWwPMT1oKI/p7fMXuJ/THdTosjzCBTzyz/aju0zFsu3w8g5rSLFIW6eSiUzEMPXD1 61D6g0+5g2M26hy2Pr6RR7T5rFvWriFR3uK5OvpA+ErcV8dINfPvOL/3uEwEKvsaFjgd wpJD5M0WABWlPO5BFrVYaCB1etIfMw43tvhqbmsk4x05UxB2GNw/uzitT+eV8wSH+LTm oG0g== X-Gm-Message-State: AO0yUKXTxUd3gnlWrnwSe4YgtMrW/Y9+eaXVV91y8UbR1OIGdaLrr7Cz DvU2YnXrBlimEeQ2NWIVWsRxZoQLiZ7rdFsqjLweJw== X-Google-Smtp-Source: AK7set9DRSjdDSOH/ubTtnj3ZWh/l/LM/Fed+a0gXsvyWOJJR2VSCb/44EF3F4bp835JuxcLhITk3w== X-Received: by 2002:a17:902:cf46:b0:199:1682:9175 with SMTP id e6-20020a170902cf4600b0019916829175mr3264866plg.8.1676935594414; Mon, 20 Feb 2023 15:26:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 02/21] target/arm: Add isar_feature_aa64_rme Date: Mon, 20 Feb 2023 13:26:07 -1000 Message-Id: <20230220232626.429947-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1041; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1041.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935746160100001 Content-Type: text/plain; charset="utf-8" Add the missing field for ID_AA64PFR0, and the predicate. Disable it if EL3 is forced off by the board or command-line. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 6 ++++++ target/arm/cpu.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 12b1082537..04f000cc54 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2190,6 +2190,7 @@ FIELD(ID_AA64PFR0, SEL2, 36, 4) FIELD(ID_AA64PFR0, MPAM, 40, 4) FIELD(ID_AA64PFR0, AMU, 44, 4) FIELD(ID_AA64PFR0, DIT, 48, 4) +FIELD(ID_AA64PFR0, RME, 52, 4) FIELD(ID_AA64PFR0, CSV2, 56, 4) FIELD(ID_AA64PFR0, CSV3, 60, 4) =20 @@ -3802,6 +3803,11 @@ static inline bool isar_feature_aa64_sel2(const ARMI= SARegisters *id) return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, SEL2) !=3D 0; } =20 +static inline bool isar_feature_aa64_rme(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RME) !=3D 0; +} + static inline bool isar_feature_aa64_vh(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, VH) !=3D 0; diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 876ab8f3bf..83685ed247 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1947,6 +1947,10 @@ static void arm_cpu_realizefn(DeviceState *dev, Erro= r **errp) cpu->isar.id_dfr0 =3D FIELD_DP32(cpu->isar.id_dfr0, ID_DFR0, COPSD= BG, 0); cpu->isar.id_aa64pfr0 =3D FIELD_DP64(cpu->isar.id_aa64pfr0, ID_AA64PFR0, EL3, 0); + + /* Disable the realm management extension, which requires EL3. */ + cpu->isar.id_aa64pfr0 =3D FIELD_DP64(cpu->isar.id_aa64pfr0, + ID_AA64PFR0, RME, 0); } =20 if (!cpu->has_el2) { --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935676; cv=none; d=zohomail.com; s=zohoarc; b=YFiUjcaqyk5O39ok+5SRyToSKS9YtrTvdNBC8vhoUNLPz+12Dm1SUmyWTYoBI14wVB81A0YDb5CbjRyJIJMzrQQfJ67PaIZ0r+Se4y+snyV8qTj4vN1bNYGaydkaT/7uC2Q0j4akQtRQh6otcdmlht4h2ECTfqed8HdR6Rh0vsM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935676; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hZ5RT1U0BG9RauOmNkX+PjAfe5FY1kHSfa1bLxVuTYM=; b=enPZ22tCa8Y+chkpeVb3KyRcBRt6bUbI6mPPNhq3nq5lJKwSBZbxGwmXIdoHc6T7lERlXzgvFWPDNPtxczhaO1Y7P4uA7bBb1al3941omtXiG7NMEJ4/w6d+H39UCxgc4okH6Qr0oCh+oRJEW5O4sTSNFpPT9YFlAmJFtgiiEgs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935676335467.4018907234072; Mon, 20 Feb 2023 15:27:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYP-0003jH-Iv; Mon, 20 Feb 2023 18:26:41 -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 1pUFYN-0003fz-Es for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:39 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYL-0000Ik-7g for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:39 -0500 Received: by mail-pj1-x1033.google.com with SMTP id co23-20020a17090afe9700b002341fadc370so2882801pjb.1 for ; Mon, 20 Feb 2023 15:26:36 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:35 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hZ5RT1U0BG9RauOmNkX+PjAfe5FY1kHSfa1bLxVuTYM=; b=E2OkhAs2HCKxNlV+9SVLVsK/KuBKP8cJAZXpzrPE21cl4xOpbpBS7Mg5sfPF1fVoBQ VWlNC5Gz0VEte2zKHbBJF2kyDiimS5TDzla/7U+Ra963vRvZ9KmIKZ45GBflYf7dQoxC tQu6PIxDFq4AveWjokaxrneVHwcmTZdCRCO+Yr8Spj/opVkxrsNgGijsOUL5/Tfd5nZw M84mtPP+cLM2nRxKKPd5+KXmpNqPx0EKV43p5/em1uJehucCzU8wdavXA35jrKKEo5Fx +TgvfPIJRan0+s5jzXAg4S6EsKf3G6WnlTSPZRzticvtBXko9XtvJCtdQxkDqPRt0Xt5 Fyzg== 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 :subject:date:message-id:reply-to; bh=hZ5RT1U0BG9RauOmNkX+PjAfe5FY1kHSfa1bLxVuTYM=; b=JPOa7ScbWPw54a+tD2Cc0+xvUhme+/Xg6WOIeoO/K4YL9M0fmn6kKj7GhIvqL1KzMy 8pB9Q1KXKKdO7RwYndteOWzwVf4Xod4Hbrn8HNeo5ksW1InCm/h5hoXlWFZdOOGOsgxW 19zi4+SPrbl3RwDpO/7ahLkIScpycFNoTiDpf4lokE7hTeGbiobWq4MpCBQGqcamidIO h7GhUCs4JsnT2sGNJ3b1ZD96Um/3R/T4Mk2xucLqh5go2eq//3YTav5PXGDID0VvXzVp 1S3TDv/vz8W4DMyXgAusabxIp+4MltfhBx84Bp+VfLSRP2MoNZPlyg6p/lsy9jqHoFSi MhTQ== X-Gm-Message-State: AO0yUKX/JkG8iEFO7iKrrt/UX6lm6yy5k8TgtqHRTZ8eEryX1tGwvjQC x7pmJlHnwcTW9bfKbo1lpuf7ojx6B4Wcrvh8xD0= X-Google-Smtp-Source: AK7set8AbGisuB4FQIkveEb4QdUC/a/EvKGae4+Oy62LwwaQrzCfPSQbgU7F87mj/bAqSuRknVAJkA== X-Received: by 2002:a17:903:2291:b0:19b:33c0:4092 with SMTP id b17-20020a170903229100b0019b33c04092mr3327416plh.24.1676935595910; Mon, 20 Feb 2023 15:26:35 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 03/21] target/arm: Update SCR and HCR for RME Date: Mon, 20 Feb 2023 13:26:08 -1000 Message-Id: <20230220232626.429947-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935677773100001 Content-Type: text/plain; charset="utf-8" Define the missing SCR and HCR bits, allow SCR_NSE and {SCR,HCR}_GPF to be set, and invalidate TLBs when NSE changes. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 +++-- target/arm/helper.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 04f000cc54..486baf3924 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1650,7 +1650,7 @@ static inline void xpsr_write(CPUARMState *env, uint3= 2_t val, uint32_t mask) #define HCR_TERR (1ULL << 36) #define HCR_TEA (1ULL << 37) #define HCR_MIOCNCE (1ULL << 38) -/* RES0 bit 39 */ +#define HCR_TME (1ULL << 39) #define HCR_APK (1ULL << 40) #define HCR_API (1ULL << 41) #define HCR_NV (1ULL << 42) @@ -1659,7 +1659,7 @@ static inline void xpsr_write(CPUARMState *env, uint3= 2_t val, uint32_t mask) #define HCR_NV2 (1ULL << 45) #define HCR_FWB (1ULL << 46) #define HCR_FIEN (1ULL << 47) -/* RES0 bit 48 */ +#define HCR_GPF (1ULL << 48) #define HCR_TID4 (1ULL << 49) #define HCR_TICAB (1ULL << 50) #define HCR_AMVOFFEN (1ULL << 51) @@ -1724,6 +1724,7 @@ static inline void xpsr_write(CPUARMState *env, uint3= 2_t val, uint32_t mask) #define SCR_TRNDR (1ULL << 40) #define SCR_ENTP2 (1ULL << 41) #define SCR_GPF (1ULL << 48) +#define SCR_NSE (1ULL << 62) =20 #define HSTR_TTEE (1 << 16) #define HSTR_TJDBX (1 << 17) diff --git a/target/arm/helper.c b/target/arm/helper.c index 07d4100365..42d94e0904 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1875,6 +1875,9 @@ static void scr_write(CPUARMState *env, const ARMCPRe= gInfo *ri, uint64_t value) if (cpu_isar_feature(aa64_fgt, cpu)) { valid_mask |=3D SCR_FGTEN; } + if (cpu_isar_feature(aa64_rme, cpu)) { + valid_mask |=3D SCR_NSE | SCR_GPF; + } } else { valid_mask &=3D ~(SCR_RW | SCR_ST); if (cpu_isar_feature(aa32_ras, cpu)) { @@ -1904,10 +1907,10 @@ static void scr_write(CPUARMState *env, const ARMCP= RegInfo *ri, uint64_t value) env->cp15.scr_el3 =3D value; =20 /* - * If SCR_EL3.NS changes, i.e. arm_is_secure_below_el3, then + * If SCR_EL3.{NS,NSE} changes, i.e. change of security state, * we must invalidate all TLBs below EL3. */ - if (changed & SCR_NS) { + if (changed & (SCR_NS | SCR_NSE)) { tlb_flush_by_mmuidx(env_cpu(env), (ARMMMUIdxBit_E10_0 | ARMMMUIdxBit_E20_0 | ARMMMUIdxBit_E10_1 | @@ -5655,6 +5658,9 @@ static void do_hcr_write(CPUARMState *env, uint64_t v= alue, uint64_t valid_mask) if (cpu_isar_feature(aa64_fwb, cpu)) { valid_mask |=3D HCR_FWB; } + if (cpu_isar_feature(aa64_rme, cpu)) { + valid_mask |=3D HCR_GPF; + } } =20 if (cpu_isar_feature(any_evt, cpu)) { --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935684; cv=none; d=zohomail.com; s=zohoarc; b=k2xaAD74w8qdrXCTgeYLxSEjfJH/4npKSkEXi4pSTkRie31DFaMovf1pvOVtSoTjSOeyjEy/4hjOZ8XTbdzcNQe2p4P2MxDfXyhgyv6xcxkWRkZ0OajfpvpugmzcwDsR2ysrrlKaD1uNCLBnrCzBrRVGOwa6EwrfR0i8QUWISHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935684; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mH7WMawWeBvYR6Z0Haoxdyec8KWtOPSKDJkaIsK10I4=; b=NNx0Ad9giLJ7qa4JY8ypCPBggkEyH21HU7wOhth0scEnL8LcIMfsffPJno7TSWSoqzE58xOCppsTi2zheWgFeL5FN8WaFTK/X0fWouIn6O8y/U8MNBscbCMpXDLo/+v3n1DpiUMhk3aLYVK9AVxzDSt/T17AznXExNXmz5rg7eY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935684292765.5909710174976; Mon, 20 Feb 2023 15:28:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYQ-0003jT-2H; Mon, 20 Feb 2023 18:26:42 -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 1pUFYO-0003hz-NU for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:40 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYN-0000JI-30 for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:40 -0500 Received: by mail-pj1-x1029.google.com with SMTP id o16so2898252pjp.3 for ; Mon, 20 Feb 2023 15:26:38 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:36 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mH7WMawWeBvYR6Z0Haoxdyec8KWtOPSKDJkaIsK10I4=; b=nvVlE274/tK3ExBcRxUCRMfxZtDgtaXLidNuM/h88+aFHH42rv7txuXLvJPi9QU3wp ST3DgC+FuSc9yh1ld89cVh8o5MzK4ChA+tekjIZtUTZMgjePQEXcsVExbfOk3wkgPjR6 szfXtyxk6/gBYsYUgJhNnK74rj5n2OMRlsp2ByKYR3+j4/3oYY3a33LB5HlZfmd7CttQ E19d0y8QLxc+Fn6AGFhR5OgB395ccd2I0JvbuZ+yg5OjyDEIqzQow16l2Sgu/dW6gC9+ NDl6gvlS0FYXm5FpT++5WMa/v32hP4GbcesMDaNh/Zv5vsQj2dfTAMasFn6EBUjGaEgU ev0Q== 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 :subject:date:message-id:reply-to; bh=mH7WMawWeBvYR6Z0Haoxdyec8KWtOPSKDJkaIsK10I4=; b=ldRfqjNF6JHUuZdgD9R7b82vObrJDTHuAubhrEBCGk18t+5VOVIiwdme31wD8sZzHl jmnHYMDRs2yMKmyMCysD0wCCtlYTZvOPYB+f+DMTOnXxOI8pFLF4Rm9PDYgVHpjowHhN d5HqgecPFinvYkJllL4i69VYLngr4LVGMprSYkMUUyrboat62qUcqqfWm74sg3yonJVd rUzcfLnk3sJEijzgBYDaFrDiLNwEOdPZxa8vhHpbwhRzwV9UYtOB09m5B5V0Gkvadyve zkjRTBEZhsdtLKqxeXkI1F+RvQCOwRhXgFC/SGvVLrxppTryOTd2qmDzY18eBpHwHun1 vShQ== X-Gm-Message-State: AO0yUKUTiBPeKwDsQKOXqmVvS2X0FtX+iN8CTqGhD+8/2KFgggSjD04H fO96LqOlHc+GxKJPHfB7OflD249ZnWQdj3KdrE0= X-Google-Smtp-Source: AK7set/ojI5y0ewTqhcrZqUuupCMsC9mJ+gKhvVZNFaMgw+NgMyhWXSBV9GcEdcFcPeiEKtSw7G2Mw== X-Received: by 2002:a17:903:2808:b0:19a:ea48:730c with SMTP id kp8-20020a170903280800b0019aea48730cmr1919079plb.46.1676935597252; Mon, 20 Feb 2023 15:26:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 04/21] target/arm: SCR_EL3.NS may be RES1 Date: Mon, 20 Feb 2023 13:26:09 -1000 Message-Id: <20230220232626.429947-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935685817100001 Content-Type: text/plain; charset="utf-8" With RME, SEL2 must also be present to support secure state. The NS bit is RES1 if SEL2 is not present. Signed-off-by: Richard Henderson --- target/arm/helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/arm/helper.c b/target/arm/helper.c index 42d94e0904..2ebca3e2b6 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1856,6 +1856,9 @@ static void scr_write(CPUARMState *env, const ARMCPRe= gInfo *ri, uint64_t value) } if (cpu_isar_feature(aa64_sel2, cpu)) { valid_mask |=3D SCR_EEL2; + } else if (cpu_isar_feature(aa64_rme, cpu)) { + /* With RME and without SEL2, NS is RES1 (R_GSWWH, I_DJJQJ). */ + value |=3D SCR_NS; } if (cpu_isar_feature(aa64_mte, cpu)) { valid_mask |=3D SCR_ATA; --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935724; cv=none; d=zohomail.com; s=zohoarc; b=jusjjSgx1U0G9uwaOL1YQ9hTMLB9Hzj6YJTMjSJcU0KsEJFzwlYIejq50vEEU2c3z4vppD+TtnjE6+qQ5itBEq4xusf55tkwfFRRNEPOM6c98wn5MUQbY1BMWj3+WxkpxEPlki/7agnuA6dfa9u3kRNxfMWj5DKojru6+CC0m/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935724; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kl7nsc9p6BIDSk+FSIUoP/kFXINcnp5gsZ8dnkbWdwU=; b=IDnmr62ZECtle80RPktpcttTwPyxTg7aIcmQo4MnH5Mmnm/zOYQ9YrPnhOTAQQQ95ilF4ZCR4Wi4upiMEWvDpWYNFFRIClHRbK0jGMz1vdIHXG9eyulWvKLWi4FpGH2JDWNn5+yoq6sgKdM/ZKKSq6AbQifeZeRf+vq2lxLFjx4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935724298300.4563674971729; Mon, 20 Feb 2023 15:28:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYR-0003lv-8S; Mon, 20 Feb 2023 18:26:43 -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 1pUFYQ-0003k7-Dd for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:42 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYO-0000Jl-Jo for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:42 -0500 Received: by mail-pj1-x102c.google.com with SMTP id g14so2820879pjb.2 for ; Mon, 20 Feb 2023 15:26:40 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:38 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kl7nsc9p6BIDSk+FSIUoP/kFXINcnp5gsZ8dnkbWdwU=; b=Px0cV/J3cA5nxUSIyPH4WmDlrGXHRfWGHBHPLb9gDVPzqc5DzcQKJSyzqE9QlLI+KI MP0WilTKdLe3pXXIH00HYQMyLsx62Pkqwk6Y/a1VB8bKZpfoW7Bizazr8jZyFSj1hq6E ASiaiGbPrGXVTacms4f97QAVgpX0FOiK7uTEzf/O7O6hgzlAo4w3JO1TwflpHZIYew6h yICHGIc4nhDV/KSmGXZXjCaqbpkBKNmpArxqGPrBv4FQy+j/U1cr+O25W87Znir7OezD 6WLLXy02d05orj0R+erfCvNimihBA7U8BBPh4y3xIYrv5aXNr7uAJtTLWTEX1Ok7JS/i 1+uw== 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 :subject:date:message-id:reply-to; bh=kl7nsc9p6BIDSk+FSIUoP/kFXINcnp5gsZ8dnkbWdwU=; b=PC5wWMlxetl122Buf3Vbf72iPYj+p0/4b7bMnJ5s9q9mIXBwy1wexqAAasoSvc9LH6 gRe5Md8G+rAZAWO07lMd9fmLzVa07dc+PcqYx2ZnClBqs0F16lPsDHIIcmcXyHIErLwn xSSoO/RSgShkll1Lbr9FpQnJssGkEZsXYFtVrvmHzzkHObLZ39yo9oTe/w9IQ6759tkC B8wxozJiY2woENNmMX36Ne9JGYz+qDLYf5tqqZj0eRm5Ez3aMmKWoM+pOMWwWtu/T4l5 j4ZtQ15y1pPyILxgmEB7JTNnhMifMZOb8WeqoDd0/lVBWmWaKSN0ga/le7/DRmF13R4r EcGg== X-Gm-Message-State: AO0yUKX6UfbgJnXUpOzFlIA0CBpRMF75VtnTQu7lkqzAOlYCvQlzFdIw DvB8MuR7yS8bZ3iaYCuHV9t6IFramAcHU+EaUT4= X-Google-Smtp-Source: AK7set9oK+uPEm+3vH1QvaKLOxUIa34L6NNOmCGnpIXWHgpDNECQNLjTZp2y1S/wpJm7LV9tqytOWg== X-Received: by 2002:a17:902:d4cc:b0:19b:dc8:c67b with SMTP id o12-20020a170902d4cc00b0019b0dc8c67bmr2462597plg.50.1676935598836; Mon, 20 Feb 2023 15:26:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 05/21] target/arm: Add RME cpregs Date: Mon, 20 Feb 2023 13:26:10 -1000 Message-Id: <20230220232626.429947-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935726001100010 Content-Type: text/plain; charset="utf-8" This includes GPCCR, GPTBR, MFAR, the TLB flush insns PAALL, PAALLOS, RPALOS, RPAOS, and the cache flush insns CIPAPA and CIGDPAPA. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 19 +++++++++++ target/arm/helper.c | 83 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 486baf3924..6a97c727d1 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -541,6 +541,11 @@ typedef struct CPUArchState { uint64_t fgt_read[2]; /* HFGRTR, HDFGRTR */ uint64_t fgt_write[2]; /* HFGWTR, HDFGWTR */ uint64_t fgt_exec[1]; /* HFGITR */ + + /* RME registers */ + uint64_t gpccr_el3; + uint64_t gptbr_el3; + uint64_t mfar_el3; } cp15; =20 struct { @@ -1043,6 +1048,7 @@ struct ArchCPU { uint64_t reset_cbar; uint32_t reset_auxcr; bool reset_hivecs; + uint8_t reset_l0gptsz; =20 /* * Intermediate values used during property parsing. @@ -2336,6 +2342,19 @@ FIELD(MVFR1, SIMDFMAC, 28, 4) FIELD(MVFR2, SIMDMISC, 0, 4) FIELD(MVFR2, FPMISC, 4, 4) =20 +FIELD(GPCCR, PPS, 0, 3) +FIELD(GPCCR, IRGN, 8, 2) +FIELD(GPCCR, ORGN, 10, 2) +FIELD(GPCCR, SH, 12, 2) +FIELD(GPCCR, PGS, 14, 2) +FIELD(GPCCR, GPC, 16, 1) +FIELD(GPCCR, GPCP, 17, 1) +FIELD(GPCCR, L0GPTSZ, 20, 4) + +FIELD(MFAR, FPA, 12, 40) +FIELD(MFAR, NSE, 62, 1) +FIELD(MFAR, NS, 63, 1) + QEMU_BUILD_BUG_ON(ARRAY_SIZE(((ARMCPU *)0)->ccsidr) <=3D R_V7M_CSSELR_INDE= X_MASK); =20 /* If adding a feature bit which corresponds to a Linux ELF diff --git a/target/arm/helper.c b/target/arm/helper.c index 2ebca3e2b6..c769218763 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6932,6 +6932,83 @@ static const ARMCPRegInfo sme_reginfo[] =3D { .access =3D PL2_RW, .accessfn =3D access_esm, .type =3D ARM_CP_CONST, .resetvalue =3D 0 }, }; + +static void tlbi_aa64_paall_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + CPUState *cs =3D env_cpu(env); + + tlb_flush(cs); +} + +static void gpccr_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + /* L0GPTSZ is RO; other bits not mentioned are RES0. */ + uint64_t rw_mask =3D R_GPCCR_PPS_MASK | R_GPCCR_IRGN_MASK | + R_GPCCR_ORGN_MASK | R_GPCCR_SH_MASK | R_GPCCR_PGS_MASK | + R_GPCCR_GPC_MASK | R_GPCCR_GPCP_MASK; + + env->cp15.gpccr_el3 =3D (value & rw_mask) | (env->cp15.gpccr_el3 & ~rw= _mask); +} + +static void gpccr_reset(CPUARMState *env, const ARMCPRegInfo *ri) +{ + env->cp15.gpccr_el3 =3D FIELD_DP64(0, GPCCR, L0GPTSZ, + env_archcpu(env)->reset_l0gptsz); +} + +static void tlbi_aa64_paallos_write(CPUARMState *env, const ARMCPRegInfo *= ri, + uint64_t value) +{ + CPUState *cs =3D env_cpu(env); + + tlb_flush_all_cpus_synced(cs); +} + +static const ARMCPRegInfo rme_reginfo[] =3D { + { .name =3D "GPCCR_EL3", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 6, .crn =3D 2, .crm =3D 1, .opc2 =3D 6, + .access =3D PL3_RW, .writefn =3D gpccr_write, .resetfn =3D gpccr_res= et, + .fieldoffset =3D offsetof(CPUARMState, cp15.gpccr_el3) }, + { .name =3D "GPTBR_EL3", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 6, .crn =3D 2, .crm =3D 1, .opc2 =3D 4, + .access =3D PL3_RW, .fieldoffset =3D offsetof(CPUARMState, cp15.gptb= r_el3) }, + { .name =3D "MFAR_EL3", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 6, .crn =3D 6, .crm =3D 0, .opc2 =3D 5, + .access =3D PL3_RW, .fieldoffset =3D offsetof(CPUARMState, cp15.mfar= _el3) }, + { .name =3D "TLBI_PAALL", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 1, .opc1 =3D 6, .crn =3D 8, .crm =3D 7, .opc2 =3D 4, + .access =3D PL3_W, .type =3D ARM_CP_NO_RAW, + .writefn =3D tlbi_aa64_paall_write }, + { .name =3D "TLBI_PAALLOS", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 1, .opc1 =3D 6, .crn =3D 8, .crm =3D 1, .opc2 =3D 4, + .access =3D PL3_W, .type =3D ARM_CP_NO_RAW, + .writefn =3D tlbi_aa64_paallos_write }, + /* + * QEMU does not have a way to invalidate by physical address, thus + * invalidating a range of physical addresses is accomplished by + * flushing all tlb entries in the outer sharable domain, + * just like PAALLOS. + */ + { .name =3D "TLBI_RPALOS", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 1, .opc1 =3D 6, .crn =3D 8, .crm =3D 4, .opc2 =3D 7, + .access =3D PL3_W, .type =3D ARM_CP_NO_RAW, + .writefn =3D tlbi_aa64_paallos_write }, + { .name =3D "TLBI_RPAOS", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 1, .opc1 =3D 6, .crn =3D 8, .crm =3D 4, .opc2 =3D 3, + .access =3D PL3_W, .type =3D ARM_CP_NO_RAW, + .writefn =3D tlbi_aa64_paallos_write }, + { .name =3D "DC_CIPAPA", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 1, .opc1 =3D 6, .crn =3D 7, .crm =3D 14, .opc2 =3D 1, + .access =3D PL3_W, .type =3D ARM_CP_NOP }, +}; + +static const ARMCPRegInfo rme_mte_reginfo[] =3D { + { .name =3D "DC_CIGDPAPA", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 1, .opc1 =3D 6, .crn =3D 7, .crm =3D 14, .opc2 =3D 5, + .access =3D PL3_W, .type =3D ARM_CP_NOP }, +}; #endif /* TARGET_AARCH64 */ =20 static void define_pmu_regs(ARMCPU *cpu) @@ -9123,6 +9200,12 @@ void register_cp_regs_for_features(ARMCPU *cpu) if (cpu_isar_feature(aa64_tlbios, cpu)) { define_arm_cp_regs(cpu, tlbios_reginfo); } + if (cpu_isar_feature(aa64_rme, cpu)) { + define_arm_cp_regs(cpu, rme_reginfo); + if (cpu_isar_feature(aa64_mte, cpu)) { + define_arm_cp_regs(cpu, rme_mte_reginfo); + } + } #ifndef CONFIG_USER_ONLY /* Data Cache clean instructions up to PoP */ if (cpu_isar_feature(aa64_dcpop, cpu)) { --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935666; cv=none; d=zohomail.com; s=zohoarc; b=N/YjnEyvHFH9yXwraJWz4tV+6/eIVtsMoBxvrD5aTLQ8Wr8Nqs8Vz99y2XTk6mOXcFnckKD3HnBIf24QMqrb2EHnceqaVTQBNzZT6JId2VZ0eI6kV+CTnCIa8/NXSV7yqpOMVZ5d54DHB5k/7WP1Cuzi7JYnCG1Y1WIT/b7GtsM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935666; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HJ0eXW5VRS0QeP2fz4cJY2IGgEGJA0/xJ9DiQojdrZw=; b=Gf5KXUcYdQVnVg2OQp7T51QyyqGtCS0peSPhXQbTEisg2JRSvV6EXbHMRmqrzZAwZdQAYeeywMBbV1jIlAEJXVE1UIsvamGOEwrZWcElbSx8YIxz1lha6cE920TK5lSygi/kGtJBM2fMJmCQGfAnznuX+TgKKP2AUfOC5unZMEg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935666058320.3040469414216; Mon, 20 Feb 2023 15:27:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYT-0003nz-47; Mon, 20 Feb 2023 18:26:45 -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 1pUFYR-0003mk-SF for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:43 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYQ-0000KX-2z for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:43 -0500 Received: by mail-pl1-x635.google.com with SMTP id s5so3043308plg.0 for ; Mon, 20 Feb 2023 15:26:41 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:39 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HJ0eXW5VRS0QeP2fz4cJY2IGgEGJA0/xJ9DiQojdrZw=; b=yRDIFZ1hKKh+Ou/BE6Reih1mFOWMoebCVm+cMDPqZ5c2cxlG3tAA0RHtzgEN72RHpX YpuG5AhWzbkZssamR3klbLOas5k8adeIG2NNdcNUpVymjT+fRiVg/HAo9yqYy0iDWKzb LntjVnqTsUNdlcLbWaeXFAilncY2iqyD2PQPAkiSUX3N21wO/OmZbx4tHFFYP3GdBo5o rTN9ZDlg0QbxYMxXGrbC1/lhBkQgP7cCdDSWFtx90hePJ5booLmPRYe0x4NIuvzT04FY +arhbBeWhjZmWcVxIcPUsgYOUtLReCKO5g4t/A2BgZJEdA5zUxlqHUAYp8X7jPXOUm3b f19A== 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 :subject:date:message-id:reply-to; bh=HJ0eXW5VRS0QeP2fz4cJY2IGgEGJA0/xJ9DiQojdrZw=; b=OOtEpXkOoh06AautUquuKM5NeMsRWXcs3729ESx1TG1rMIp7BtyKgHfl+Vo2L4hP9E FR9iE0t+jNBzfzCZk74IzLl58ISXE1Dk6VcgYN14z+JHX6X2u/s4N8dXOUNw80w7S3qQ pICGchsEMBVN8DVvOtL0pZpnjo79HRTTBUWyMan/20Cq1PBlUP6l4hGIvkYQfu6QpSUt Iqum37Gy0EfoEOyE5T16Pc/I71AKHHKQoER2OTgNyy1mvdU3VGf4kLPq2GEvvMkK5Lkd wBWRpMBJGp911ZIvDB6YB/QG7yhDR8zJou5AKYovHASrM5a/hOMvmTScDrkpUj4sQ0XP gldA== X-Gm-Message-State: AO0yUKUb2UphRMwip1QVkAg4a5OTf1HnbUfHuSPjW0ToLyw/f84PQ/SJ fBC6lwEz7igDdJK8NXlNo23WIAU/vFkiSUyNGOw= X-Google-Smtp-Source: AK7set8uLXMJEHQMvBDud3DXie/a6XxWkqIZkk/i3KQ1gpZeFOhb/A6DJpJIgYpKywHHCrx2FhDkQA== X-Received: by 2002:a17:902:e84b:b0:19a:ba6f:b179 with SMTP id t11-20020a170902e84b00b0019aba6fb179mr5320893plg.29.1676935600266; Mon, 20 Feb 2023 15:26:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 06/21] target/arm: Introduce ARMSecuritySpace Date: Mon, 20 Feb 2023 13:26:11 -1000 Message-Id: <20230220232626.429947-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935667724100007 Content-Type: text/plain; charset="utf-8" Introduce both the enumeration and functions to retrieve the current state, and state outside of EL3. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 86 +++++++++++++++++++++++++++++++++++---------- target/arm/helper.c | 54 ++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 18 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 6a97c727d1..1b982dc94c 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2409,23 +2409,53 @@ static inline int arm_feature(CPUARMState *env, int= feature) =20 void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp); =20 +/* + * ARM v9 security states. + * The ordering of the enumeration corresponds to the low 2 bits + * of the GPI value, and (except for Root) the concat of NSE:NS. + */ + +typedef enum ARMSecuritySpace { + ARMSS_Secure =3D 0, + ARMSS_NonSecure =3D 1, + ARMSS_Root =3D 2, + ARMSS_Realm =3D 3, +} ARMSecuritySpace; + +/* Return true if @space is secure, in the pre-v9 sense. */ +static inline bool arm_space_is_secure(ARMSecuritySpace space) +{ + return space =3D=3D ARMSS_Secure || space =3D=3D ARMSS_Root; +} + +/* Return the ARMSecuritySpace for @secure, assuming !RME or EL[0-2]. */ +static inline ARMSecuritySpace arm_secure_to_space(bool secure) +{ + return secure ? ARMSS_Secure : ARMSS_NonSecure; +} + #if !defined(CONFIG_USER_ONLY) -/* Return true if exception levels below EL3 are in secure state, - * or would be following an exception return to that level. - * Unlike arm_is_secure() (which is always a question about the - * _current_ state of the CPU) this doesn't care about the current - * EL or mode. +/** + * arm_security_space_below_el3: + * @env: cpu context + * + * Return the security space of exception levels below EL3, following + * an exception return to those levels. Unlike arm_security_space, + * this doesn't care about the current EL. + */ +ARMSecuritySpace arm_security_space_below_el3(CPUARMState *env); + +/** + * arm_is_secure_below_el3: + * @env: cpu context + * + * Return true if exception levels below EL3 are in secure state, + * or would be following an exception return to those levels. */ static inline bool arm_is_secure_below_el3(CPUARMState *env) { - if (arm_feature(env, ARM_FEATURE_EL3)) { - return !(env->cp15.scr_el3 & SCR_NS); - } else { - /* If EL3 is not supported then the secure state is implementation - * defined, in which case QEMU defaults to non-secure. - */ - return false; - } + ARMSecuritySpace ss =3D arm_security_space_below_el3(env); + return ss =3D=3D ARMSS_Secure; } =20 /* Return true if the CPU is AArch64 EL3 or AArch32 Mon */ @@ -2444,13 +2474,23 @@ static inline bool arm_is_el3_or_mon(CPUARMState *e= nv) return false; } =20 -/* Return true if the processor is in secure state */ +/** + * arm_security_space: + * @env: cpu context + * + * Return the current security space of the cpu. + */ +ARMSecuritySpace arm_security_space(CPUARMState *env); + +/** + * arm_is_secure: + * @env: cpu context + * + * Return true if the processor is in secure state. + */ static inline bool arm_is_secure(CPUARMState *env) { - if (arm_is_el3_or_mon(env)) { - return true; - } - return arm_is_secure_below_el3(env); + return arm_space_is_secure(arm_security_space(env)); } =20 /* @@ -2469,11 +2509,21 @@ static inline bool arm_is_el2_enabled(CPUARMState *= env) } =20 #else +static inline ARMSecuritySpace arm_security_space_below_el3(CPUARMState *e= nv) +{ + return ARMSS_NonSecure; +} + static inline bool arm_is_secure_below_el3(CPUARMState *env) { return false; } =20 +static inline ARMSecuritySpace arm_security_space(CPUARMState *env) +{ + return ARMSS_NonSecure; +} + static inline bool arm_is_secure(CPUARMState *env) { return false; diff --git a/target/arm/helper.c b/target/arm/helper.c index c769218763..13af812215 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -12535,3 +12535,57 @@ void aarch64_sve_change_el(CPUARMState *env, int o= ld_el, } } #endif + +#ifndef CONFIG_USER_ONLY +ARMSecuritySpace arm_security_space(CPUARMState *env) +{ + /* + * If EL3 is not supported then the secure state is implementation + * defined, in which case QEMU defaults to non-secure. + */ + if (!arm_feature(env, ARM_FEATURE_EL3)) { + return ARMSS_NonSecure; + } + + /* Check for AArch64 EL3 or AArch32 Mon. */ + if (is_a64(env)) { + if (extract32(env->pstate, 2, 2) =3D=3D 3) { + if (cpu_isar_feature(aa64_rme, env_archcpu(env))) { + return ARMSS_Root; + } else { + return ARMSS_Secure; + } + } + } else { + if ((env->uncached_cpsr & CPSR_M) =3D=3D ARM_CPU_MODE_MON) { + return ARMSS_Secure; + } + } + + return arm_security_space_below_el3(env); +} + +ARMSecuritySpace arm_security_space_below_el3(CPUARMState *env) +{ + /* + * If EL3 is not supported then the secure state is implementation + * defined, in which case QEMU defaults to non-secure. + */ + if (!arm_feature(env, ARM_FEATURE_EL3)) { + return ARMSS_NonSecure; + } + + /* + * Note NSE cannot be set without RME, and NSE & !NS is Reserved. + * Ignoring NSE when !NS retains consistency without having to + * modify other predicates. + */ + if (!(env->cp15.scr_el3 & SCR_NS)) { + return ARMSS_Secure; + } else if (env->cp15.scr_el3 & SCR_NSE) { + return ARMSS_Realm; + } else { + return ARMSS_NonSecure; + } +} +#endif /* !CONFIG_USER_ONLY */ --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935640; cv=none; d=zohomail.com; s=zohoarc; b=DwXYwI4bNfmWyReXgckHzI/BUNMNB6Gocop/dsf0B1C6vF064ltWzBSpJu+zZBem5GfgH+uYcYs0eUtHal1F6qjC83OCTZkz+48kfOXfDLSDznxpqCrRqdwG3DYWeEKe9K/a4Gn11WOa/Lj7IYUneorOchvT8niq7Md7pGTpWWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935640; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0zAr88doy4l35/U8kOUIKFNAL46N655Bwwt/mOy9kK4=; b=j7fRzlg5a+/8D3tRqnu2Pf9d9qgKpjYeRWf9RfYfrVfcQMFCV6IEPTMsff1vn+pQkg6WyF6qe2MQVLokN7lmH5N/MT3l5A0lWPmeuCXpUqbGMdn44rOD0VjgK01ytn/50fw4CRZs/1b9o0exHWuJU8kRQ64rNEsWFoHxv9tv25c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935640804426.2406948067196; Mon, 20 Feb 2023 15:27:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYV-0003uG-1I; Mon, 20 Feb 2023 18:26:47 -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 1pUFYT-0003nu-0f for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:45 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYR-0000LF-Gn for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:44 -0500 Received: by mail-pj1-x102b.google.com with SMTP id d1-20020a17090a3b0100b00229ca6a4636so3132876pjc.0 for ; Mon, 20 Feb 2023 15:26:43 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:41 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0zAr88doy4l35/U8kOUIKFNAL46N655Bwwt/mOy9kK4=; b=S6sEYxzGxO3bfpesCdh8SoyA0w8Nm+dMMgqv79oqg0RDkdwJjOTil9JPT1AYe84ZfJ 8uFmlk38dM+iwRR8uf3a/sbjebwSrt2ssGewg89oYl5uC+hcKAaXoN34UJT616QEIJi/ Apx6uKufuN0zUtOiLGE/84w921NlCwj3BT3rXBwyAgEvAR1I1Wj5HFY4SJaWFmu10VvP uo1J4+J01t8e4cZTg/fUCeLq3Mbg90DMJ6Cj1dqgaI+2cKB/H9ragb9IITl3TEb6D8xK JtgyOiLnEtSTZ0Q+2ICVic+p0wxn1Wl307BUP39tz1zoCGb++2jOaYVUaRTQEQSl6Mba odFQ== 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 :subject:date:message-id:reply-to; bh=0zAr88doy4l35/U8kOUIKFNAL46N655Bwwt/mOy9kK4=; b=DAZZNPTDCq1GBiTKwWGMC3BtSedsLiVBdF/6OyEIgxzraRdeIw5ZOLEZa3w2Zi9hFC LUx1lsRpA5+gNmwjmoBLisqhZan5x27GYnjz5wAyDbui9wNaVgtumDfCE3dAnNLftQEq fMijhCoZP4GtU4IbYO0rZCtJm8EnhNb8sRd7p/yeEudJfrIsch7XjwFjjN9wOI9Y9smG eyIiQBSDX20o7RlNjIc4YYDZaB2JmycIRsowJwkuPODSuoWrqiQBjBKUlBgYDLEY9sgp DfH6FnCDR8gkPlz45jh4ItGanugiIzbfpQsvmOGZydSAa92BKCsYE0lmhjdDJLfZk23t CwgQ== X-Gm-Message-State: AO0yUKWdxm3kHbG2RoPVLLfY0l33aZOiTlTxILgBByC/rCfH2mXCUWP1 jPOnJO5ejRlA0nPYOpFeeGbhiiAaawLWi47JNjA= X-Google-Smtp-Source: AK7set/ZFP7U6SrNTDIu7u4TiG5IwHUP/QlbENdv9lLJ+U4BYG3qaZCXyi/zypcALle5rT5ktfETJQ== X-Received: by 2002:a17:902:d2c3:b0:19a:80c9:2cd7 with SMTP id n3-20020a170902d2c300b0019a80c92cd7mr3138209plc.47.1676935601902; Mon, 20 Feb 2023 15:26:41 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 07/21] include/exec/memattrs: Add two bits of space to MemTxAttrs Date: Mon, 20 Feb 2023 13:26:12 -1000 Message-Id: <20230220232626.429947-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935641626100005 Content-Type: text/plain; charset="utf-8" We will need 2 bits to represent ARMSecurityState. Do not attempt to replace or widen secure, even though it logically overlaps the new field -- there are uses within e.g. hw/block/pflash_cfi01.c, which don't know anything specific about ARM. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/exec/memattrs.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index 9fb98bc1ef..d04170aa27 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -29,10 +29,17 @@ typedef struct MemTxAttrs { * "didn't specify" if necessary. */ unsigned int unspecified:1; - /* ARM/AMBA: TrustZone Secure access + /* + * ARM/AMBA: TrustZone Secure access * x86: System Management Mode access */ unsigned int secure:1; + /* + * ARM: ArmSecuritySpace. This partially overlaps secure, but it is + * easier to have both fields to assist code that does not understand + * ARMv9 RME, or no specific knowledge of ARM at all (e.g. pflash). + */ + unsigned int space:2; /* Memory access is usermode (unprivileged) */ unsigned int user:1; /* --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935634; cv=none; d=zohomail.com; s=zohoarc; b=Xly34iex23fqIKd9gf07PeNqbQkUC6CUDrvLAhlp20ywOUO34XQMqJzdhduR5nOtj9LrRsUNb9W4qUy7rnEpBfgOXa/TSTKAtr1sTPsxf/n1IpxwIyHd26dOCBFkbKJhpjt0Ym4JR3lcTiMD0ic8tcuBcmAqyUQaJTtcdqtJ22E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935634; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=16mYzaWfQJouACxZdLwovOfwLxSjOAqgX/IHmcrs7RY=; b=fN3Y9pJ8IymxZL2lZRcKIV/yuB/Zo3HfZQXVFwrnYn/B3IWNntBoR2butxNYOmGtOyqJ2tSsmxYQEI/Tnucvf7akBmoXwy/VlvwW2zztdQoknnGYozNjB5W/sPLbEPJ68HsZh5ebmCbMyywMJlfx/fum2GaV3yxjVKptoXMAADs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935634064468.5768576883079; Mon, 20 Feb 2023 15:27:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYW-0003zB-2m; Mon, 20 Feb 2023 18:26: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 1pUFYU-0003sx-Jj for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:46 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYS-0000M3-Rg for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:46 -0500 Received: by mail-pj1-x102b.google.com with SMTP id pt11so3453804pjb.1 for ; Mon, 20 Feb 2023 15:26:44 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:43 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=16mYzaWfQJouACxZdLwovOfwLxSjOAqgX/IHmcrs7RY=; b=Bvk251OcJAGbyvjnVS1iUWZTpk8ZIqihTDIrgBX5pCz1tLqGdqevHp0Q/l45wce+m/ DPx5ljItbUYNmDS6DP2/osBOX0x7jqXFe7RqxkNhadrnrJcXCLptnKxhDpq6UruPOx5z OiCBidO76lkBjYARUYwvXaXzl3TOC5irZQVPCxHKeT7ohuK72rbemYvwAcbOwg+dZgNc q1TPFDtce3xrzpm/XuSNVAY5TfRhfqliW4KPhc/edsZhL7PDpFCj87mwLGDtMoZE8/48 X27eMTscQou9Lu/gmIY4DsTsJBaMYv3Eje8RJmuakuRkPStM4bTsIdx0YptTyzAr7dQY GODw== 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 :subject:date:message-id:reply-to; bh=16mYzaWfQJouACxZdLwovOfwLxSjOAqgX/IHmcrs7RY=; b=o7+uzQZdManxgtd/MBAqWIg663IkiG1ObgNEWBR/HSuK8V+aEHN0DhepXaJyhI2Fbx 8itGmxNVnm3SbOt6EL8hlr1DovGyNZYyckWWlIVWwy8wWgY41iCCCQhzsXIr5zdBpKCO ERx6r9jCVb8AWMB58bGNgjGiDuYHDohqVWHoicPzFFu4Rdn9htjhakM5jQG+uTd+2UWN yyN6af846xiHD4hVr+ZDKmEYT06xXeK6GvFNYXsO6PDRcNeM+aQxmDlwUwWhaQEk2OzO 5g/K8vuZsCSxK8Xqj8d3SOIRLI6fuQM7SUPE9QBnqYBka1nlXP3Tqksbvc2ZPMUWd1Az MAQA== X-Gm-Message-State: AO0yUKXQExaj+v3FDqobJvZnkihspyKLjW13tIqq0PASIYLAqK4LSR3e bCt8pOPTVoIxRRN5TQ9GBfq7mWVqKbPioK7TAEo= X-Google-Smtp-Source: AK7set/JRVWiR4/gR7bCYL7RIqD3ytJmswevpXmoQFYio30vKqOo9YG3VeuUUEmvzGq6p19AwXyCfw== X-Received: by 2002:a17:902:ba93:b0:196:6ec0:345a with SMTP id k19-20020a170902ba9300b001966ec0345amr4157755pls.25.1676935603520; Mon, 20 Feb 2023 15:26:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 08/21] target/arm: Adjust the order of Phys and Stage2 ARMMMUIdx Date: Mon, 20 Feb 2023 13:26:13 -1000 Message-Id: <20230220232626.429947-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935635666100001 Content-Type: text/plain; charset="utf-8" It will be helpful to have ARMMMUIdx_Phys_* to be in the same relative order as ARMSecuritySpace enumerators. This requires the adjustment to the nstable check. While there, check for being in secure state rather than rely on clearing the low bit making no change to non-secure state. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 12 ++++++------ target/arm/ptw.c | 12 +++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 1b982dc94c..c9585390d4 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2854,18 +2854,18 @@ typedef enum ARMMMUIdx { ARMMMUIdx_E2 =3D 6 | ARM_MMU_IDX_A, ARMMMUIdx_E3 =3D 7 | ARM_MMU_IDX_A, =20 - /* TLBs with 1-1 mapping to the physical address spaces. */ - ARMMMUIdx_Phys_NS =3D 8 | ARM_MMU_IDX_A, - ARMMMUIdx_Phys_S =3D 9 | ARM_MMU_IDX_A, - /* * Used for second stage of an S12 page table walk, or for descriptor * loads during first stage of an S1 page table walk. Note that both * are in use simultaneously for SecureEL2: the security state for * the S2 ptw is selected by the NS bit from the S1 ptw. */ - ARMMMUIdx_Stage2 =3D 10 | ARM_MMU_IDX_A, - ARMMMUIdx_Stage2_S =3D 11 | ARM_MMU_IDX_A, + ARMMMUIdx_Stage2_S =3D 8 | ARM_MMU_IDX_A, + ARMMMUIdx_Stage2 =3D 9 | ARM_MMU_IDX_A, + + /* TLBs with 1-1 mapping to the physical address spaces. */ + ARMMMUIdx_Phys_S =3D 10 | ARM_MMU_IDX_A, + ARMMMUIdx_Phys_NS =3D 11 | ARM_MMU_IDX_A, =20 /* * These are not allocated TLBs and are used only for AT system diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 6fb72fb086..5ed5bb5039 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1410,16 +1410,14 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1= Translate *ptw, descaddr |=3D (address >> (stride * (4 - level))) & indexmask; descaddr &=3D ~7ULL; nstable =3D extract32(tableattrs, 4, 1); - if (nstable) { + if (nstable && ptw->in_secure) { /* * Stage2_S -> Stage2 or Phys_S -> Phys_NS - * Assert that the non-secure idx are even, and relative order. + * Assert the relative order of the secure/non-secure indexes. */ - QEMU_BUILD_BUG_ON((ARMMMUIdx_Phys_NS & 1) !=3D 0); - QEMU_BUILD_BUG_ON((ARMMMUIdx_Stage2 & 1) !=3D 0); - QEMU_BUILD_BUG_ON(ARMMMUIdx_Phys_NS + 1 !=3D ARMMMUIdx_Phys_S); - QEMU_BUILD_BUG_ON(ARMMMUIdx_Stage2 + 1 !=3D ARMMMUIdx_Stage2_S); - ptw->in_ptw_idx &=3D ~1; + QEMU_BUILD_BUG_ON(ARMMMUIdx_Phys_S + 1 !=3D ARMMMUIdx_Phys_NS); + QEMU_BUILD_BUG_ON(ARMMMUIdx_Stage2_S + 1 !=3D ARMMMUIdx_Stage2); + ptw->in_ptw_idx +=3D 1; ptw->in_secure =3D false; } if (!S1_ptw_translate(env, ptw, descaddr, fi)) { --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935784; cv=none; d=zohomail.com; s=zohoarc; b=FpUlqiCmb2QJxCJ2Z6ak/BPxFMrLjaZiQ55YaOgmcGBvnpnfHbVWCKxwR6pQvi4qZPSggGTrJc0mP3UghA504DKhybLK4Q6Qy8yGOjBJO3pOhfG3whV8PGvOtfxhYYPfG5b4S8WfCzC/c9L0gjO3GmvD1Jg5HwEHFrVmEwc7VOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935784; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3Gj4J+B5iGnKsOwsF9h/fX8hbpbRCBs9B/CdgKeQjUk=; b=EgCGtFVA7sCAHVBLUmd5mDqwndPhOtVPz7OI31PO4l7ld6hTNRBHMjD33Ef8lfZY9IAN25f39C/hj1hIQYnlnjc1FKcKi1CouOnyPQ80Ye8/r+/mEwZT7NA5JcR0erKua/ShB4fV0C1bnZ9y20MdEld1qMjvzHjgmIIC9VnWRf8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935784506530.6729943909352; Mon, 20 Feb 2023 15:29:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYX-00041P-N5; Mon, 20 Feb 2023 18:26:49 -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 1pUFYW-0003za-6Z for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:48 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYU-0000NW-IW for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:47 -0500 Received: by mail-pl1-x62e.google.com with SMTP id p1so1087511plg.7 for ; Mon, 20 Feb 2023 15:26:46 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:44 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3Gj4J+B5iGnKsOwsF9h/fX8hbpbRCBs9B/CdgKeQjUk=; b=fyUIuc71rFe6mvaGGhsFVhXHBMoqkDcb07bruBj7PkPGxVyMePN7RvurG38Z2WNCpR TT7GK3ds7K6Fh9x/n76Z7lCLaxrecWdQMff1KBUjYUefxAqUnfglNL2Je+Z3Ae6Jj1sG wmykFuXQGXqtdOZXEETNcbXS7fjcCs1yhp+wr2JBBplJ8y2uTtm+M7Q2bhhBh3xLTJfh /yduR+5rHfF+8Df7hv7DEhQlrzhKGWwVZBUxV6Zzj7zhtJyLggF0KuU8Cf6+yaPNcysO OQFIB2uDzwa20r6n8GSEbjr2fXKIi8Y445/mYU0EuPd6TFpAp8BhYVA+IhAfX5aQdI7Z rBiQ== 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 :subject:date:message-id:reply-to; bh=3Gj4J+B5iGnKsOwsF9h/fX8hbpbRCBs9B/CdgKeQjUk=; b=frSBeeZwI7Z+JovoAkVTdMwnd/xDXSBdhlK3oOHxw2aS0oaN9qmM5jXJ1HY51PkSL2 0NOtVVs/m86NLn55ooX7ZkhAqL13Uy/K6RE94BNmA/mQXb2dW+iASJUEI98vymmk7vuJ Hkk+b5vxlgWAGo5ul5sOSU7dkXr3gDQmNUFGY0+j8mum9gznkSOlUYJ+RqIdOUaDnlub C5P7kRL/dsnRcF6dzwdEyodox4wVsiIxcwBJaI3jepr6EHCsjBex4m5VOC8NtTdmjC29 QUhCal+WfdFVlBwCqaV/o8bwnL+BsnajOzPQpJuCvd1aI21WorYoxC71NJWr+BfSqAv2 QAbA== X-Gm-Message-State: AO0yUKXrpMMSUpHlmUPxFhgieAXpZoj2+WwNwsEzg4isk/wxcLlCM+Ja VllMCpyOyk6vROsQxoMO/3x1MUo69Miei/XbJnQ= X-Google-Smtp-Source: AK7set+9mwf5GRPMulaedM2hkyubiq0hjGl780yo/ctXz+J0kqn0p5HkJm/SoBkQuQcmZuElsdvbNQ== X-Received: by 2002:a05:6a20:8f0d:b0:b8:71b7:b903 with SMTP id b13-20020a056a208f0d00b000b871b7b903mr3989221pzk.31.1676935605303; Mon, 20 Feb 2023 15:26:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 09/21] target/arm: Introduce ARMMMUIdx_Phys_{Realm,Root} Date: Mon, 20 Feb 2023 13:26:14 -1000 Message-Id: <20230220232626.429947-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935786282100006 Content-Type: text/plain; charset="utf-8" With FEAT_RME, there are four physical address spaces. For now, just define the symbols, and mention them in the same spots as the other Phys indexes in ptw.c. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu-param.h | 2 +- target/arm/cpu.h | 23 +++++++++++++++++++++-- target/arm/ptw.c | 10 ++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index 53cac9c89b..8dfd7a0bb6 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -47,6 +47,6 @@ bool guarded; #endif =20 -#define NB_MMU_MODES 12 +#define NB_MMU_MODES 14 =20 #endif diff --git a/target/arm/cpu.h b/target/arm/cpu.h index c9585390d4..4bafe8340e 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2864,8 +2864,10 @@ typedef enum ARMMMUIdx { ARMMMUIdx_Stage2 =3D 9 | ARM_MMU_IDX_A, =20 /* TLBs with 1-1 mapping to the physical address spaces. */ - ARMMMUIdx_Phys_S =3D 10 | ARM_MMU_IDX_A, - ARMMMUIdx_Phys_NS =3D 11 | ARM_MMU_IDX_A, + ARMMMUIdx_Phys_S =3D 10 | ARM_MMU_IDX_A, + ARMMMUIdx_Phys_NS =3D 11 | ARM_MMU_IDX_A, + ARMMMUIdx_Phys_Root =3D 12 | ARM_MMU_IDX_A, + ARMMMUIdx_Phys_Realm =3D 13 | ARM_MMU_IDX_A, =20 /* * These are not allocated TLBs and are used only for AT system @@ -2929,6 +2931,23 @@ typedef enum ARMASIdx { ARMASIdx_TagS =3D 3, } ARMASIdx; =20 +static inline ARMMMUIdx arm_space_to_phys(ARMSecuritySpace space) +{ + /* Assert the relative order of the physical mmu indexes. */ + QEMU_BUILD_BUG_ON(ARMSS_Secure !=3D 0); + QEMU_BUILD_BUG_ON(ARMMMUIdx_Phys_NS !=3D ARMMMUIdx_Phys_S + ARMSS_NonS= ecure); + QEMU_BUILD_BUG_ON(ARMMMUIdx_Phys_Root !=3D ARMMMUIdx_Phys_S + ARMSS_Ro= ot); + QEMU_BUILD_BUG_ON(ARMMMUIdx_Phys_Realm !=3D ARMMMUIdx_Phys_S + ARMSS_R= ealm); + + return ARMMMUIdx_Phys_S + space; +} + +static inline ARMSecuritySpace arm_phys_to_space(ARMMMUIdx idx) +{ + assert(idx >=3D ARMMMUIdx_Phys_S && idx <=3D ARMMMUIdx_Phys_Realm); + return idx - ARMMMUIdx_Phys_S; +} + static inline bool arm_v7m_csselr_razwi(ARMCPU *cpu) { /* If all the CLIDR.Ctypem bits are 0 there are no caches, and diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 5ed5bb5039..5a0c5edc88 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -182,8 +182,10 @@ static bool regime_translation_disabled(CPUARMState *e= nv, ARMMMUIdx mmu_idx, case ARMMMUIdx_E3: break; =20 - case ARMMMUIdx_Phys_NS: case ARMMMUIdx_Phys_S: + case ARMMMUIdx_Phys_NS: + case ARMMMUIdx_Phys_Root: + case ARMMMUIdx_Phys_Realm: /* No translation for physical address spaces. */ return true; =20 @@ -2632,8 +2634,10 @@ static bool get_phys_addr_disabled(CPUARMState *env,= target_ulong address, switch (mmu_idx) { case ARMMMUIdx_Stage2: case ARMMMUIdx_Stage2_S: - case ARMMMUIdx_Phys_NS: case ARMMMUIdx_Phys_S: + case ARMMMUIdx_Phys_NS: + case ARMMMUIdx_Phys_Root: + case ARMMMUIdx_Phys_Realm: break; =20 default: @@ -2830,6 +2834,8 @@ static bool get_phys_addr_with_struct(CPUARMState *en= v, S1Translate *ptw, switch (mmu_idx) { case ARMMMUIdx_Phys_S: case ARMMMUIdx_Phys_NS: + case ARMMMUIdx_Phys_Root: + case ARMMMUIdx_Phys_Realm: /* Checking Phys early avoids special casing later vs regime_el. */ return get_phys_addr_disabled(env, address, access_type, mmu_idx, is_secure, result, fi); --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935685; cv=none; d=zohomail.com; s=zohoarc; b=apE1/8qNLcJl6OmJZGtK73NmeWzltbjGl4N9BP9YGi0i6a/54+xiRMwgdWnDEME4QobFSAgzkRoBaN2ASNTA23eNLjRcrHs+o21ZKZWxeRkDjvdgWq4YMoNxrEKrLtwGpvr4iZes8aMCNJQSCcddvjsY9wTy9ASdbNwyshekCIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935685; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HSjxF6mCj3nhvrrRuM2gW/YQifDnxgBhjfPXSNiexPo=; b=VEWLn56SBMdnpnLlQoqkMRCHDpKvaFgcL1WY1PAxYCmKDzpw+o3TJ9IER7H74rbfJhO90oEyWpjtIhZnvcBHhQBTdZeJfiQn1EOCzQiHtwkFKIDap000Y/AV9ivmPVH5y648NZPvTiHOVrsZ2qD5yAOv22XWTOjg1rWwX/Fy7i4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935685501723.6960813449916; Mon, 20 Feb 2023 15:28:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYb-00044A-0g; Mon, 20 Feb 2023 18:26:53 -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 1pUFYY-00042d-5M for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:50 -0500 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYW-0000OP-2l for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:49 -0500 Received: by mail-pj1-x1044.google.com with SMTP id ei9-20020a17090ae54900b002349a303ca5so2877293pjb.4 for ; Mon, 20 Feb 2023 15:26:47 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:46 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HSjxF6mCj3nhvrrRuM2gW/YQifDnxgBhjfPXSNiexPo=; b=Hn5CVnt26hi2yiCnvLgQOUl1+yYVFihNbd4J/h2R7kWNESobiiiz7tDXYm0kRljD1X mR5Kjref2/gmuTIbCASXlyl6wD+WDOq8qlOGBphAxe4be5Tq5yK9L0+C5jvWPgQXfukQ YrhMcq7u6Wp4FOqkW0U9KYJWvez9Ac0za6j9fGIGP7PscWw7KqsgqMPd7Ifn7nmpvVsY WWhmmzlHNcRik0YsMAo3EifHSKOMcPB5hA/3W7AZxqNJ2vxMjTf4McXjiEqmW+W8T/0R blBSUD6w6f1aZVaZpoUWNkYG2yusF4J6iecfYW8fggyjdVCKVuz4t6S2XrNY1t5BKOrB L5xA== 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 :subject:date:message-id:reply-to; bh=HSjxF6mCj3nhvrrRuM2gW/YQifDnxgBhjfPXSNiexPo=; b=Qb0ZjJi2upHhikJXcneal/fuSRQ123lrQpGgTrgwdtP+NgvR9u8LFs58hHBuwrcze4 VhU5o6x0PC1KDdTUFRsXcB22FwjCRw1c47duJWSROvA6X7YOiAg5s5+xFzfIky4jbc/x sGZTF4iK82zkyy+39BoXumKErcqXx1v5spGmrni3qFJTMT7QXuvdhl/Ip3yQIljktvIh AMvN9a0FANoKxrAe38s8kbTNVYh+dMoCtQS6ZRg04ZeUQbzRaqggYqC7i4hH2iyjgxP0 MPN9kEIc7DRC0ZGtlrxAV4RV8ry1WW24fq6g30Cm6H2nG/fQikJaMx+STVwTXm7X2dLf SxyA== X-Gm-Message-State: AO0yUKVqm3KJtl/7GwinOtg3R0o7eOYJ/Ek0lppWJiZaqt6yskqi79Mn tAnZzad7UDu3Q+xv6SzXguQsyOP0kG85P6zuQY0MuQ== X-Google-Smtp-Source: AK7set+is2YTRiTj+jTA+bocJJ2QWYyLGJ24N0TqNUyFdbiNHh6bQVGyT+iXebUDXe58065szIYzRw== X-Received: by 2002:a05:6a21:32a9:b0:bc:930e:4165 with SMTP id yt41-20020a056a2132a900b000bc930e4165mr3395695pzb.15.1676935606791; Mon, 20 Feb 2023 15:26:46 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 10/21] target/arm: Pipe ARMSecuritySpace through ptw.c Date: Mon, 20 Feb 2023 13:26:15 -1000 Message-Id: <20230220232626.429947-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1044.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935685864100003 Content-Type: text/plain; charset="utf-8" Add input and output space members to S1Translate. Set and adjust them in S1_ptw_translate, and the various points at which we drop secure state. Initialize the space in get_phys_addr; for now leave get_phys_addr_with_secure considering only secure vs non-secure spaces. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 95 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 5a0c5edc88..7745287a46 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -19,11 +19,13 @@ typedef struct S1Translate { ARMMMUIdx in_mmu_idx; ARMMMUIdx in_ptw_idx; + ARMSecuritySpace in_space; bool in_secure; bool in_debug; bool out_secure; bool out_rw; bool out_be; + ARMSecuritySpace out_space; hwaddr out_virt; hwaddr out_phys; void *out_host; @@ -218,6 +220,7 @@ static bool S2_attrs_are_device(uint64_t hcr, uint8_t a= ttrs) static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, hwaddr addr, ARMMMUFaultInfo *fi) { + ARMSecuritySpace space =3D ptw->in_space; bool is_secure =3D ptw->in_secure; ARMMMUIdx mmu_idx =3D ptw->in_mmu_idx; ARMMMUIdx s2_mmu_idx =3D ptw->in_ptw_idx; @@ -234,7 +237,8 @@ static bool S1_ptw_translate(CPUARMState *env, S1Transl= ate *ptw, if (regime_is_stage2(s2_mmu_idx)) { S1Translate s2ptw =3D { .in_mmu_idx =3D s2_mmu_idx, - .in_ptw_idx =3D is_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_P= hys_NS, + .in_ptw_idx =3D arm_space_to_phys(space), + .in_space =3D space, .in_secure =3D is_secure, .in_debug =3D true, }; @@ -292,10 +296,17 @@ static bool S1_ptw_translate(CPUARMState *env, S1Tran= slate *ptw, } =20 /* Check if page table walk is to secure or non-secure PA space. */ - ptw->out_secure =3D (is_secure - && !(pte_secure + if (is_secure) { + bool out_secure =3D !(pte_secure ? env->cp15.vstcr_el2 & VSTCR_SW - : env->cp15.vtcr_el2 & VTCR_NSW)); + : env->cp15.vtcr_el2 & VTCR_NSW); + if (!out_secure) { + is_secure =3D false; + space =3D ARMSS_NonSecure; + } + } + ptw->out_secure =3D is_secure; + ptw->out_space =3D space; ptw->out_be =3D regime_translation_big_endian(env, mmu_idx); return true; =20 @@ -326,7 +337,10 @@ static uint32_t arm_ldl_ptw(CPUARMState *env, S1Transl= ate *ptw, } } else { /* Page tables are in MMIO. */ - MemTxAttrs attrs =3D { .secure =3D ptw->out_secure }; + MemTxAttrs attrs =3D { + .secure =3D ptw->out_secure, + .space =3D ptw->out_space, + }; AddressSpace *as =3D arm_addressspace(cs, attrs); MemTxResult result =3D MEMTX_OK; =20 @@ -369,7 +383,10 @@ static uint64_t arm_ldq_ptw(CPUARMState *env, S1Transl= ate *ptw, #endif } else { /* Page tables are in MMIO. */ - MemTxAttrs attrs =3D { .secure =3D ptw->out_secure }; + MemTxAttrs attrs =3D { + .secure =3D ptw->out_secure, + .space =3D ptw->out_space, + }; AddressSpace *as =3D arm_addressspace(cs, attrs); MemTxResult result =3D MEMTX_OK; =20 @@ -875,6 +892,7 @@ static bool get_phys_addr_v6(CPUARMState *env, S1Transl= ate *ptw, * regime, because the attribute will already be non-secure. */ result->f.attrs.secure =3D false; + result->f.attrs.space =3D ARMSS_NonSecure; } result->f.phys_addr =3D phys_addr; return false; @@ -1579,6 +1597,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Tr= anslate *ptw, * regime, because the attribute will already be non-secure. */ result->f.attrs.secure =3D false; + result->f.attrs.space =3D ARMSS_NonSecure; } =20 /* When in aarch64 mode, and BTI is enabled, remember GP in the TLB. = */ @@ -2363,6 +2382,7 @@ static bool get_phys_addr_pmsav8(CPUARMState *env, ui= nt32_t address, */ if (sattrs.ns) { result->f.attrs.secure =3D false; + result->f.attrs.space =3D ARMSS_NonSecure; } else if (!secure) { /* * NS access to S memory must fault. @@ -2712,6 +2732,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, = S1Translate *ptw, bool is_secure =3D ptw->in_secure; bool ret, ipa_secure, s2walk_secure; ARMCacheAttrs cacheattrs1; + ARMSecuritySpace ipa_space, s2walk_space; bool is_el0; uint64_t hcr; =20 @@ -2724,20 +2745,24 @@ static bool get_phys_addr_twostage(CPUARMState *env= , S1Translate *ptw, =20 ipa =3D result->f.phys_addr; ipa_secure =3D result->f.attrs.secure; + ipa_space =3D result->f.attrs.space; if (is_secure) { /* Select TCR based on the NS bit from the S1 walk. */ s2walk_secure =3D !(ipa_secure ? env->cp15.vstcr_el2 & VSTCR_SW : env->cp15.vtcr_el2 & VTCR_NSW); + s2walk_space =3D arm_secure_to_space(s2walk_secure); } else { assert(!ipa_secure); s2walk_secure =3D false; + s2walk_space =3D ipa_space; } =20 is_el0 =3D ptw->in_mmu_idx =3D=3D ARMMMUIdx_Stage1_E0; ptw->in_mmu_idx =3D s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Sta= ge2; - ptw->in_ptw_idx =3D s2walk_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_= NS; + ptw->in_ptw_idx =3D arm_space_to_phys(s2walk_space); ptw->in_secure =3D s2walk_secure; + ptw->in_space =3D s2walk_space; =20 /* * S1 is done, now do S2 translation. @@ -2825,11 +2850,12 @@ static bool get_phys_addr_with_struct(CPUARMState *= env, S1Translate *ptw, ARMMMUIdx s1_mmu_idx; =20 /* - * The page table entries may downgrade secure to non-secure, but - * cannot upgrade an non-secure translation regime's attributes - * to secure. + * The page table entries may downgrade Secure to NonSecure, but + * cannot upgrade a NonSecure translation regime's attributes + * to Secure or Realm. */ result->f.attrs.secure =3D is_secure; + result->f.attrs.space =3D ptw->in_space; =20 switch (mmu_idx) { case ARMMMUIdx_Phys_S: @@ -2871,7 +2897,7 @@ static bool get_phys_addr_with_struct(CPUARMState *en= v, S1Translate *ptw, =20 default: /* Single stage and second stage uses physical for ptw. */ - ptw->in_ptw_idx =3D is_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_= NS; + ptw->in_ptw_idx =3D arm_space_to_phys(ptw->in_space); break; } =20 @@ -2946,6 +2972,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, targ= et_ulong address, S1Translate ptw =3D { .in_mmu_idx =3D mmu_idx, .in_secure =3D is_secure, + .in_space =3D arm_secure_to_space(is_secure), }; return get_phys_addr_with_struct(env, &ptw, address, access_type, result, fi); @@ -2955,7 +2982,10 @@ bool get_phys_addr(CPUARMState *env, target_ulong ad= dress, MMUAccessType access_type, ARMMMUIdx mmu_idx, GetPhysAddrResult *result, ARMMMUFaultInfo *fi) { - bool is_secure; + S1Translate ptw =3D { + .in_mmu_idx =3D mmu_idx, + }; + ARMSecuritySpace ss; =20 switch (mmu_idx) { case ARMMMUIdx_E10_0: @@ -2968,30 +2998,55 @@ bool get_phys_addr(CPUARMState *env, target_ulong a= ddress, case ARMMMUIdx_Stage1_E1: case ARMMMUIdx_Stage1_E1_PAN: case ARMMMUIdx_E2: - is_secure =3D arm_is_secure_below_el3(env); + ss =3D arm_security_space_below_el3(env); break; case ARMMMUIdx_Stage2: + /* + * For Secure EL2, we need this index to be NonSecure; + * otherwise this will already be NonSecure or Realm. + */ + ss =3D arm_security_space_below_el3(env); + if (ss =3D=3D ARMSS_Secure) { + ss =3D ARMSS_NonSecure; + } + break; case ARMMMUIdx_Phys_NS: case ARMMMUIdx_MPrivNegPri: case ARMMMUIdx_MUserNegPri: case ARMMMUIdx_MPriv: case ARMMMUIdx_MUser: - is_secure =3D false; + ss =3D ARMSS_NonSecure; break; - case ARMMMUIdx_E3: case ARMMMUIdx_Stage2_S: case ARMMMUIdx_Phys_S: case ARMMMUIdx_MSPrivNegPri: case ARMMMUIdx_MSUserNegPri: case ARMMMUIdx_MSPriv: case ARMMMUIdx_MSUser: - is_secure =3D true; + ss =3D ARMSS_Secure; + break; + case ARMMMUIdx_E3: + if (arm_feature(env, ARM_FEATURE_AARCH64) && + cpu_isar_feature(aa64_rme, env_archcpu(env))) { + ss =3D ARMSS_Root; + } else { + ss =3D ARMSS_Secure; + } + break; + case ARMMMUIdx_Phys_Root: + ss =3D ARMSS_Root; + break; + case ARMMMUIdx_Phys_Realm: + ss =3D ARMSS_Realm; break; default: g_assert_not_reached(); } - return get_phys_addr_with_secure(env, address, access_type, mmu_idx, - is_secure, result, fi); + + ptw.in_space =3D ss; + ptw.in_secure =3D arm_space_is_secure(ss); + return get_phys_addr_with_struct(env, &ptw, address, access_type, + result, fi); } =20 hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, @@ -2999,9 +3054,11 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *c= s, vaddr addr, { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; + ARMSecuritySpace ss =3D arm_security_space(env); S1Translate ptw =3D { .in_mmu_idx =3D arm_mmu_idx(env), - .in_secure =3D arm_is_secure(env), + .in_space =3D ss, + .in_secure =3D arm_space_is_secure(ss), .in_debug =3D true, }; GetPhysAddrResult res =3D {}; --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935633; cv=none; d=zohomail.com; s=zohoarc; b=EhlrQsHPzIX4eHmrGYfLPgJuStunfUMjvOX8mi3DQ8xe+3NfRFWQQPAinyyYBdP3dJyBaqbeSQXlVJBccP/f0SxTbkfHpPX9xW+jplohT2gmj5An6DnBEYfWAQAEb3TtKNuBR0RK8fPXevXFYvUmOBD9EEoG0qRaqjDteBlqhxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935633; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9O4rQ+1tSrDA/VIHaikB47RvthTap5eXu1DpMH/jhqs=; b=MJjzndDL8jAvN8PnKV4pKkBP+ogGS8HR/z+EEeWIrHYe4PTNeFybi0N5T1/KhaCE6C/Rca7gUI0gegyhMLRVFsl9GGcU7jA/VuHeFb17o2YA4QixeD8sd/cv1GxWXG7FVuWZqwfsugaMtRYDeqb2jHEaxBS7Qzw1TVzMkq/+T4Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167693563397040.34221808406619; Mon, 20 Feb 2023 15:27:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYc-00048M-5m; Mon, 20 Feb 2023 18:26:54 -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 1pUFYZ-00043a-Os for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:51 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYX-0000Or-NT for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:51 -0500 Received: by mail-pl1-x636.google.com with SMTP id e5so4173347plg.8 for ; Mon, 20 Feb 2023 15:26:49 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:47 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9O4rQ+1tSrDA/VIHaikB47RvthTap5eXu1DpMH/jhqs=; b=A7/KCoOvzdkchqGOJQIfJM9hQTufU2tNpCTEO9VwXDuY3E49vaflRpzqnfGj3L7wj8 PzSsZGiEDQm36f5zCTtlpyrTCSmCzotgP4daU2b1/s+YLmcOTRxBlP/Yoadhl3UcOWta qa4OL9tAHQzVeHvDwQfMnDlC9U3MxtnrHlYF5diehNDjmrABFwEqt6iqEeCwhkJ09cSa lFX1gqWKE+s8LUNTySJATjVjRx7yxUphN8com+DzFHF0HjZ9yr/EzDPN7SUUxj33aafn uDAW+L9IWYfL1jp0xFib/LAb8HJjP2LFBnY7zq55ZfgaL3lwYzUQKBjelkqGVfsdPfYK cHIQ== 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 :subject:date:message-id:reply-to; bh=9O4rQ+1tSrDA/VIHaikB47RvthTap5eXu1DpMH/jhqs=; b=tcSRIjR/3NmbcNfgjdyhjH9srE9bfUfXl5s4svtTogr1qeO3CdtryNoXwQmfhr8oMZ dsFEj7dRGiodpCH+EwQBH0tOHmqFMZ0WbtvW9Q38tozHmrve40Y7XUqetnpBG0QMQXZa zJXNvuU3o6zbugJPPPtCBIgYJrvqx7EHOJxjHqqmWsER91D9V5tgpBXLz7x3/ZY8rPrf xE0OMO0ScyoCgO7ism/TmcIk6AchxcifVjA0lRQxLPszsqT3CLuvwAkyTI+Vb+LSi9QD H7XIgSG/ZG5mddObMjKnhNmB4Z9dP8nBX2W5wtrbyWIENHp4zi1/3Cp2AqN8QKr3kLzR 1dhw== X-Gm-Message-State: AO0yUKUEXHudxzTG/ngajw7rMzBxBJEcqsu9WjFiQ8SJ4X8SagsDS8Mr K2/TydJZyNOCz+Qm6Pd35QGS9AkLRFQGU5/z3mw= X-Google-Smtp-Source: AK7set/GIBECsuKnFBoIRdNcqEKDqJQ5Bj0VBLXvkhaebJEu4WM7h4o4mvbBGG59YUaNFieKmuMqsw== X-Received: by 2002:a17:903:2305:b0:19a:a4fc:7f80 with SMTP id d5-20020a170903230500b0019aa4fc7f80mr6249197plh.26.1676935608092; Mon, 20 Feb 2023 15:26:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 11/21] target/arm: NSTable is RES0 for the RME EL3 regime Date: Mon, 20 Feb 2023 13:26:16 -1000 Message-Id: <20230220232626.429947-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935635667100002 Content-Type: text/plain; charset="utf-8" Test in_space instead of in_secure so that we don't switch out of Root space. Handle the output space change immediately, rather than try and combine the NSTable and NS bits later. Signed-off-by: Richard Henderson --- target/arm/ptw.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 7745287a46..d612e5f38a 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1240,7 +1240,6 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Tr= anslate *ptw, { ARMCPU *cpu =3D env_archcpu(env); ARMMMUIdx mmu_idx =3D ptw->in_mmu_idx; - bool is_secure =3D ptw->in_secure; int32_t level; ARMVAParameters param; uint64_t ttbr; @@ -1256,7 +1255,6 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Tr= anslate *ptw, uint64_t descaddrmask; bool aarch64 =3D arm_el_is_aa64(env, el); uint64_t descriptor, new_descriptor; - bool nstable; =20 /* TODO: This code does not support shareability levels. */ if (aarch64) { @@ -1417,20 +1415,19 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1= Translate *ptw, descaddrmask =3D MAKE_64BIT_MASK(0, 40); } descaddrmask &=3D ~indexmask_grainsize; - - /* - * Secure accesses start with the page table in secure memory and - * can be downgraded to non-secure at any step. Non-secure accesses - * remain non-secure. We implement this by just ORing in the NSTable/NS - * bits at each step. - */ - tableattrs =3D is_secure ? 0 : (1 << 4); + tableattrs =3D 0; =20 next_level: descaddr |=3D (address >> (stride * (4 - level))) & indexmask; descaddr &=3D ~7ULL; - nstable =3D extract32(tableattrs, 4, 1); - if (nstable && ptw->in_secure) { + + /* + * Process the NSTable bit from the previous level. This changes + * the table address space and the output space from Secure to + * NonSecure. With RME, the EL3 translation regime does not change + * from Root to NonSecure. + */ + if (extract32(tableattrs, 4, 1) && ptw->in_space =3D=3D ARMSS_Secure) { /* * Stage2_S -> Stage2 or Phys_S -> Phys_NS * Assert the relative order of the secure/non-secure indexes. @@ -1439,7 +1436,11 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1T= ranslate *ptw, QEMU_BUILD_BUG_ON(ARMMMUIdx_Stage2_S + 1 !=3D ARMMMUIdx_Stage2); ptw->in_ptw_idx +=3D 1; ptw->in_secure =3D false; + ptw->in_space =3D ARMSS_NonSecure; + result->f.attrs.secure =3D false; + result->f.attrs.space =3D ARMSS_NonSecure; } + if (!S1_ptw_translate(env, ptw, descaddr, fi)) { goto do_fault; } @@ -1542,7 +1543,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Tr= anslate *ptw, */ attrs =3D new_descriptor & (MAKE_64BIT_MASK(2, 10) | MAKE_64BIT_MASK(5= 0, 14)); if (!regime_is_stage2(mmu_idx)) { - attrs |=3D nstable << 5; /* NS */ + attrs |=3D !ptw->in_secure << 5; /* NS */ if (!param.hpd) { attrs |=3D extract64(tableattrs, 0, 2) << 53; /* XN, PXN */ /* --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935740; cv=none; d=zohomail.com; s=zohoarc; b=iCHe5uUQCmZT3eYf+2JP3NJYvLtIvQ+izhMfLRhAWtFqEQXN4phvHaVXJ2dLhFZ3gOK+y5iNJZ+Hn4FQV5I1Rrp6YF6uiv/IjWA0lLLM6U5TT/nyZ2QLoPA4HWgDMIjIYTWi8FqGgoMi0hXi2riHODQIh7pW0B1TlJ7l7RxeogA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935740; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=01eI1hEc43nacXFE44/G2p50ZjHhh23ihEX6wOuioA8=; b=DS85zn0n9D1S/YJjxJKG1Wg+LLJQBiW1CpzOGNLpyS3cIUsba8UcI3eahdA5bNlmrKjab1dclLs50gQVJpMcRECcKr2AD1HU9Rp5RRM67gx3wf81pZXIq4LefYYQZbsQ+e+kgZrn2VGdbTnOOLWtbntB7q0kAxpPlzJGCi3jro4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935740399658.5340304193513; Mon, 20 Feb 2023 15:29:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYe-0004Ev-Nx; Mon, 20 Feb 2023 18:26:56 -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 1pUFYa-00044B-Dy for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:52 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYY-0000Ly-HF for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:52 -0500 Received: by mail-pl1-x62e.google.com with SMTP id ky4so4300889plb.3 for ; Mon, 20 Feb 2023 15:26:50 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:49 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=01eI1hEc43nacXFE44/G2p50ZjHhh23ihEX6wOuioA8=; b=HLA5kCka6JXxRy3XBdm/Wk+vRHf0cF8EQuJSwUkcjrHtAdGHyfzdweVt96dBE42so2 Z2wix15PGpX8SbvT0KkC1N3XVzAXbtDf9VQH2wyQ0fzTvWI4z6Tr4kV7frDNnLpGtGY5 NrRqChIAQ0s+D68iOOvXFZOXA8Bkzz+x3/cxla6iRix7Om66gQVVw3Vk9poKirncq+Fb N0mpT6wa2o75RTWDMpuMdHFl98V6HIf4LRUdVdmnE0xnpr02BHfymqjKem8p05UA8vts eUm3QHnJDdjvqJJ1LU47LSS5LcPTjuizEYIZrN5u9lGCqigRQkhkKuKkzG0QmD83+xQ7 pKjA== 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 :subject:date:message-id:reply-to; bh=01eI1hEc43nacXFE44/G2p50ZjHhh23ihEX6wOuioA8=; b=hOER+6IoUQyKSn+NN1gosp+6cZc9nvPrTm7myITNPKWU7xCf1a9bh8dmC/lGvoPLe7 VPd17SHVZYKrtGOSvfV6yokcNJflI562/tCsGprWZTZQ/rGeb816YvInNprOdt5Zx2We WwrJKu2mjW7EkEu0EhtIrPAVkI+dVOu0CV7M1oPABgrMQI+bjszEtQ5w44whgMWLFlIN xdadkfu5Oiwh1rE1pvuqrdysBBNj56oOZolOkZlx1whvTB1l+QnE3HMzasiSLGGAeo4D Ma/bVXfZDRgqXEzeAbR+tiEJ6FNslo9xizACnf2tYnQ4odiq7/Soqqbl+JowlpZq4blk I5aw== X-Gm-Message-State: AO0yUKXekEAtjol0AiFz20A1aVNCxBsDz//h5bUSwcxLkvPHkLfDIB1y SUnsmVOqGVN7bQIV0ml+YQdiUnaYLsyxhLgBK5U= X-Google-Smtp-Source: AK7set+CSAxoGH4S3wbdlT/g3dDhx1vwft/R/emKIbg3Qag7M9J2qWU3Lp7j+Z3WOH/S6rF8iNN7pg== X-Received: by 2002:a17:902:d4c8:b0:199:30a6:376c with SMTP id o8-20020a170902d4c800b0019930a6376cmr3190508plg.68.1676935609584; Mon, 20 Feb 2023 15:26:49 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 12/21] target/arm: Handle Block and Page bits for security space Date: Mon, 20 Feb 2023 13:26:17 -1000 Message-Id: <20230220232626.429947-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935742074100002 Content-Type: text/plain; charset="utf-8" With Realm security state, bit 55 of a block or page descriptor during the stage2 walk becomes the NS bit; during the stage1 walk the bit 5 NS bit is RES0. With Root security state, bit 11 of the block or page descriptor during the stage1 walk becomes the NSE bit. Rather than collecting an NS bit and applying it later, compute the output pa space from the input pa space and unconditionally assign. This means that we no longer need to adjust the output space earlier for the NSTable bit. Signed-off-by: Richard Henderson --- target/arm/ptw.c | 91 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 18 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index d612e5f38a..a9a9a8a403 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -956,12 +956,14 @@ static int get_S2prot(CPUARMState *env, int s2ap, int= xn, bool s1_is_el0) * @mmu_idx: MMU index indicating required translation regime * @is_aa64: TRUE if AArch64 * @ap: The 2-bit simple AP (AP[2:1]) - * @ns: NS (non-secure) bit * @xn: XN (execute-never) bit * @pxn: PXN (privileged execute-never) bit + * @in_pa: The original input pa space + * @out_pa: The output pa space, modified by NSTable, NS, and NSE */ static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, - int ap, int ns, int xn, int pxn) + int ap, int xn, int pxn, + ARMSecuritySpace in_pa, ARMSecuritySpace out_pa) { bool is_user =3D regime_is_user(env, mmu_idx); int prot_rw, user_rw; @@ -982,7 +984,8 @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_i= dx, bool is_aa64, } } =20 - if (ns && arm_is_secure(env) && (env->cp15.scr_el3 & SCR_SIF)) { + if (out_pa =3D=3D ARMSS_NonSecure && in_pa =3D=3D ARMSS_Secure && + (env->cp15.scr_el3 & SCR_SIF)) { return prot_rw; } =20 @@ -1250,11 +1253,12 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1= Translate *ptw, int32_t stride; int addrsize, inputsize, outputsize; uint64_t tcr =3D regime_tcr(env, mmu_idx); - int ap, ns, xn, pxn; + int ap, xn, pxn; uint32_t el =3D regime_el(env, mmu_idx); uint64_t descaddrmask; bool aarch64 =3D arm_el_is_aa64(env, el); uint64_t descriptor, new_descriptor; + ARMSecuritySpace out_space; =20 /* TODO: This code does not support shareability levels. */ if (aarch64) { @@ -1437,8 +1441,6 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Tr= anslate *ptw, ptw->in_ptw_idx +=3D 1; ptw->in_secure =3D false; ptw->in_space =3D ARMSS_NonSecure; - result->f.attrs.secure =3D false; - result->f.attrs.space =3D ARMSS_NonSecure; } =20 if (!S1_ptw_translate(env, ptw, descaddr, fi)) { @@ -1556,15 +1558,75 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1= Translate *ptw, } =20 ap =3D extract32(attrs, 6, 2); + out_space =3D ptw->in_space; if (regime_is_stage2(mmu_idx)) { - ns =3D mmu_idx =3D=3D ARMMMUIdx_Stage2; + /* + * R_GYNXY: For stage2 in Realm security state, bit 55 is NS. + * The bit remains ignored for other security states. + */ + if (out_space =3D=3D ARMSS_Realm && extract64(attrs, 55, 1)) { + out_space =3D ARMSS_NonSecure; + } xn =3D extract64(attrs, 53, 2); result->f.prot =3D get_S2prot(env, ap, xn, s1_is_el0); } else { - ns =3D extract32(attrs, 5, 1); + int nse, ns =3D extract32(attrs, 5, 1); + switch (out_space) { + case ARMSS_Root: + /* + * R_GVZML: Bit 11 becomes the NSE field in the EL3 regime. + * R_XTYPW: NSE and NS together select the output pa space. + */ + nse =3D extract32(attrs, 11, 1); + out_space =3D (nse << 1) | ns; + if (out_space =3D=3D ARMSS_Secure && + !cpu_isar_feature(aa64_sel2, cpu)) { + out_space =3D ARMSS_NonSecure; + } + break; + case ARMSS_Secure: + if (ns) { + out_space =3D ARMSS_NonSecure; + } + break; + case ARMSS_Realm: + switch (mmu_idx) { + case ARMMMUIdx_Stage1_E0: + case ARMMMUIdx_Stage1_E1: + case ARMMMUIdx_Stage1_E1_PAN: + /* I_CZPRF: For Realm EL1&0 stage1, NS bit is RES0. */ + break; + case ARMMMUIdx_E2: + case ARMMMUIdx_E20_0: + case ARMMMUIdx_E20_2: + case ARMMMUIdx_E20_2_PAN: + /* + * R_LYKFZ, R_WGRZN: For Realm EL2 and EL2&1, + * NS changes the output to non-secure space. + */ + if (ns) { + out_space =3D ARMSS_NonSecure; + } + break; + default: + g_assert_not_reached(); + } + break; + case ARMSS_NonSecure: + /* R_QRMFF: For NonSecure state, the NS bit is RES0. */ + break; + default: + g_assert_not_reached(); + } xn =3D extract64(attrs, 54, 1); pxn =3D extract64(attrs, 53, 1); - result->f.prot =3D get_S1prot(env, mmu_idx, aarch64, ap, ns, xn, p= xn); + + /* + * Note that we modified ptw->in_space earlier for NSTable, but + * result->f.attrs retains a copy of the original security space. + */ + result->f.prot =3D get_S1prot(env, mmu_idx, aarch64, ap, xn, pxn, + result->f.attrs.space, out_space); } =20 if (!(result->f.prot & (1 << access_type))) { @@ -1591,15 +1653,8 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1T= ranslate *ptw, } } =20 - if (ns) { - /* - * The NS bit will (as required by the architecture) have no effec= t if - * the CPU doesn't support TZ or this is a non-secure translation - * regime, because the attribute will already be non-secure. - */ - result->f.attrs.secure =3D false; - result->f.attrs.space =3D ARMSS_NonSecure; - } + result->f.attrs.space =3D out_space; + result->f.attrs.secure =3D arm_space_is_secure(out_space); =20 /* When in aarch64 mode, and BTI is enabled, remember GP in the TLB. = */ if (aarch64 && cpu_isar_feature(aa64_bti, cpu)) { --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935761; cv=none; d=zohomail.com; s=zohoarc; b=iHhZ7jrgQ0YZfw/ou2tOEHu6nwb+cnf/ciZCryfYFeOwD800JlQPuBh3tJFfAFRJE9dMuXoLGRcThFdnlKepJhJcp+rbNpaAmuVPg7xH1gvsjJXVwBoYTJBxY8ySW3Zuci0ncOo9HPTU3pdgMqm0dm5CjmRwOy73OAsoD+NxE5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935761; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q2wDlc9y+ZmDdlYUvnbEL+qYl6ONKTEgAFqhyLih/rk=; b=FLpgiwSmLttCOu8QL6zuzuzWYBioCOt3LRM8MWxd5rkJA/jkCfk1O5d7DFSwpaU/S7i/Pl6ncIZIeIMwvZ25GJKTxqBvG1buuNGZFNkJrNtHLZPwdkHWS5cwy9VJGgMGJ1nBUry8zuxXPpRt2LwuQ9cvMcFuVxOHJBMAaZ4M8YM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16769357615400.4079434210505042; Mon, 20 Feb 2023 15:29:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYe-0004EY-K9; Mon, 20 Feb 2023 18:26:56 -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 1pUFYb-00046u-LU for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:53 -0500 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYZ-0000Os-SV for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:53 -0500 Received: by mail-pj1-x1032.google.com with SMTP id nw10-20020a17090b254a00b00233d7314c1cso3015542pjb.5 for ; Mon, 20 Feb 2023 15:26:51 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:50 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q2wDlc9y+ZmDdlYUvnbEL+qYl6ONKTEgAFqhyLih/rk=; b=SI9939CkfMXh2gPFkBNyfUSn311jdAXhlcxpI26CQBa3jmX48aYVUJnNUe298tv0tA /55rvZT1CahipYUH1Ds2W1emizOmKY1KMHEU2McyMcTk5Ao+cM0895YjzE0oVYAZyO9N gaQAUwBjTxhKcIBvHFgpNgWsr1lanhNcQWEz6QMY/nM8ywl9WNlJnL0Z+NoJC+M4rKw5 YlJkGHlgHVgr1LiYKywbBMqXEZpHmEO13E1a3u94o6N0MKb7RhgNEouS4cgr51/G+lhE c4x0uqPh03jiltHhtgLOENZ2EFiy6G/ANfowJLNf13Vo3+O3RfklFKG8YAJZfFVpg+Ao 0Q4Q== 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 :subject:date:message-id:reply-to; bh=Q2wDlc9y+ZmDdlYUvnbEL+qYl6ONKTEgAFqhyLih/rk=; b=YoqeTugKycJ9mJGjDnQ0btWiO8AhbOgFdf8Cht+yQ//rMk2CXlDixZP9EsBsibWeZb PcK0ho4sDhqy+8uHltztTST3HWvBFPqKveuKdUP6Y25F8Y0fjO7nPjxHCgKC3hpXUqRJ 2r+xiDHSbpUc1oryGi7gaBBM1kK+LiskJT7xEjjERhkhmsbFMd+MaAPb7op007BaIyzy 6ynyF7EegBJncjjFTeAKCW8ei5CFz4kHiZKWrUfru7b81vOSEIezuoQQ1z1Cp8Ys4NjU n9NK5nR63hFzX9B6SPrOK5UptnLohEC2WlL8DGg1EeiBERa1pABLHbnf/X/CzA9zoXb7 4VVw== X-Gm-Message-State: AO0yUKUi1XaG5dAveS1VT358/CNU3+EAC0domKdLnbKt610lbWfqNELb lt/a3VtkWl/UTp5AutgCe8TKkPahRELH4HZD6D0= X-Google-Smtp-Source: AK7set9o3MJdoyqvShsoANoAbvyvIKMD7GTRBRg6+0Flhz29P2jnqB33ViymxM1ZQZTDp7gXc+/bKw== X-Received: by 2002:a17:902:e547:b0:19a:a815:2876 with SMTP id n7-20020a170902e54700b0019aa8152876mr4075649plf.62.1676935610970; Mon, 20 Feb 2023 15:26:50 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 13/21] target/arm: Handle no-execute for Realm and Root regimes Date: Mon, 20 Feb 2023 13:26:18 -1000 Message-Id: <20230220232626.429947-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935762150100001 Content-Type: text/plain; charset="utf-8" While Root and Realm may read and write data from other spaces, neither may execute from other pa spaces. This happens for Stage1 EL3, EL2, EL2&0, but stage2 EL1&0. Signed-off-by: Richard Henderson --- target/arm/ptw.c | 52 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index a9a9a8a403..54e72baff5 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -909,7 +909,7 @@ do_fault: * @xn: XN (execute-never) bits * @s1_is_el0: true if this is S2 of an S1+2 walk for EL0 */ -static int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0) +static int get_S2prot_noexecute(int s2ap) { int prot =3D 0; =20 @@ -919,6 +919,12 @@ static int get_S2prot(CPUARMState *env, int s2ap, int = xn, bool s1_is_el0) if (s2ap & 2) { prot |=3D PAGE_WRITE; } + return prot; +} + +static int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0) +{ + int prot =3D get_S2prot_noexecute(s2ap); =20 if (cpu_isar_feature(any_tts2uxn, env_archcpu(env))) { switch (xn) { @@ -984,9 +990,39 @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_= idx, bool is_aa64, } } =20 - if (out_pa =3D=3D ARMSS_NonSecure && in_pa =3D=3D ARMSS_Secure && - (env->cp15.scr_el3 & SCR_SIF)) { - return prot_rw; + if (in_pa !=3D out_pa) { + switch (in_pa) { + case ARMSS_Root: + /* + * R_ZWRVD: permission fault for insn fetched from non-Root, + * I_WWBFB: SIF has no effect in EL3. + */ + return prot_rw; + case ARMSS_Realm: + /* + * R_PKTDS: permission fault for insn fetched from non-Realm, + * for Realm EL2 or EL2&0. The corresponding fault for EL1&0 + * happens during any stage2 translation. + */ + switch (mmu_idx) { + case ARMMMUIdx_E2: + case ARMMMUIdx_E20_0: + case ARMMMUIdx_E20_2: + case ARMMMUIdx_E20_2_PAN: + return prot_rw; + default: + break; + } + break; + case ARMSS_Secure: + if (env->cp15.scr_el3 & SCR_SIF) { + return prot_rw; + } + break; + default: + /* Input NonSecure must have output NonSecure. */ + g_assert_not_reached(); + } } =20 /* TODO have_wxn should be replaced with @@ -1563,12 +1599,16 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1= Translate *ptw, /* * R_GYNXY: For stage2 in Realm security state, bit 55 is NS. * The bit remains ignored for other security states. + * R_YMCSL: Executing an insn fetched from non-Realm causes + * a stage2 permission fault. */ if (out_space =3D=3D ARMSS_Realm && extract64(attrs, 55, 1)) { out_space =3D ARMSS_NonSecure; + result->f.prot =3D get_S2prot_noexecute(ap); + } else { + xn =3D extract64(attrs, 53, 2); + result->f.prot =3D get_S2prot(env, ap, xn, s1_is_el0); } - xn =3D extract64(attrs, 53, 2); - result->f.prot =3D get_S2prot(env, ap, xn, s1_is_el0); } else { int nse, ns =3D extract32(attrs, 5, 1); switch (out_space) { --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935740; cv=none; d=zohomail.com; s=zohoarc; b=QFsoUiQwnxL+wocBfsovLDNl6eXh0nX186oRHfnZ53gBo9SVnDr9UWulylhwrsh85dPUVvI2e9PNdsfwnY41jKOYRcYtf7u5RB67L4WN20odDBA1uocKgX8A5vRdYysBlLf5szYAdRkwj9/XkIkMvDid68h+A/ubHoLz1fiS5Zo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935740; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d4Ci3OKSOkWsuhLLCd9XsBSP6q75DdfzpORQaA+1Aqs=; b=BlmGmYtVdPdye9xUKefNF5lIL1SlHiBiW1gjcSLpHLi4512zWrmNmEE/BQjtQ94gnlgoSS/lyPrcWYnOYo60hP2Rkwwul+Z1Sy179PFbyMoW+QtPpNTrOQhvp2xvr3IitMkY/CVfsWKAezvCXpeb9YZEHerRPLEPUOPXt51FkEM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935740642240.4906528822113; Mon, 20 Feb 2023 15:29:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYj-0004Sf-EE; Mon, 20 Feb 2023 18:27:01 -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 1pUFYe-0004F6-NO for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:56 -0500 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYc-0000QK-3j for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:56 -0500 Received: by mail-pj1-x1034.google.com with SMTP id v3-20020a17090a6b0300b002341a2656e5so2795817pjj.1 for ; Mon, 20 Feb 2023 15:26:53 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:52 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d4Ci3OKSOkWsuhLLCd9XsBSP6q75DdfzpORQaA+1Aqs=; b=F6+sFcFdW1ZtAnPQO4GNXDAuyz+Q5bFePcMX6bH5wEf8dqWAfCSSbjDG47dxVIXFKa Ed7KwcyusTxKS0uEEQxt0ggaXA8AQ5pS5hRdwB727Pz7dXcT5NdzM0BVEDV+PPG/Oh5V j/PoWFd9bTplJ5jjf/Wpwf3hWeybIf/kGTfEIUlvaeT+rAS8/aLG9/XjLl0NYeyoXp8d EjM3WLdZIQqgdBlygpF3JzNRBf8TYzE3uO0/oHESxtdxlIWfIreot5dZj7fWTDCnMN6r 6xKZM856uexts1tP5D9qszL+atib9EOFNywhzIRQf5h/pGJUMWinVTJfPfI1GH8u7Wbp vQZw== 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 :subject:date:message-id:reply-to; bh=d4Ci3OKSOkWsuhLLCd9XsBSP6q75DdfzpORQaA+1Aqs=; b=a4pChJ4GZCG9/VhBopvBSMzZn7C6wSwRf4CkezygqEDSQbGU2wXR1i6GRgDVoH2uY0 Ob92eXDtp9l5UsKvvajomQ/5yxY6lZU+wLWmtWGY8EH+IuMDQbIXi25IQbKJuSPRFKhx YXY/cUHtZ5OYC6p3JIv99I25Njw+oGPOvuSWhfN4G8d75wN/x/e+WyodffVm1TZix+eW xvsn6PV+C9/QDSkkCh+/loJ0A6apiWqeciW76XVX/WFuD8XvrZMkEg07ZOpz3OaYLnhq vyo0yCswN2zp/FwiKFN1F2hwzUK8inwSOcpByI6c/7dWSVqMgDxpnDR0ebO7KGMHRIdY jGfA== X-Gm-Message-State: AO0yUKUXayJ+r2C+Un6a9YOx69uhywTJ0x0N3CyLylqmm8597pwN0AJv b8f0MW4wjeljz8y64yJ1PWiiSK48haeF3RylBF8= X-Google-Smtp-Source: AK7set+BGUPe9qHyeDlXLopDCXxbU7pNQzBon11NvGHVxsnCQkQJGzeQbea1zzxp/P4Dd7Ho/ehAsg== X-Received: by 2002:a17:902:c40d:b0:19a:8284:83a2 with SMTP id k13-20020a170902c40d00b0019a828483a2mr4647179plk.10.1676935612564; Mon, 20 Feb 2023 15:26:52 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 14/21] target/arm: Use get_phys_addr_with_struct in S1_ptw_translate Date: Mon, 20 Feb 2023 13:26:19 -1000 Message-Id: <20230220232626.429947-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935742055100001 Content-Type: text/plain; charset="utf-8" Do not provide a fast-path for physical addresses, as those will need to be validated for GPC. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 54e72baff5..6e980654be 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -234,29 +234,22 @@ static bool S1_ptw_translate(CPUARMState *env, S1Tran= slate *ptw, * From gdbstub, do not use softmmu so that we don't modify the * state of the cpu at all, including softmmu tlb contents. */ - if (regime_is_stage2(s2_mmu_idx)) { - S1Translate s2ptw =3D { - .in_mmu_idx =3D s2_mmu_idx, - .in_ptw_idx =3D arm_space_to_phys(space), - .in_space =3D space, - .in_secure =3D is_secure, - .in_debug =3D true, - }; - GetPhysAddrResult s2 =3D { }; + S1Translate s2ptw =3D { + .in_mmu_idx =3D s2_mmu_idx, + .in_ptw_idx =3D arm_space_to_phys(space), + .in_space =3D space, + .in_secure =3D is_secure, + .in_debug =3D true, + }; + GetPhysAddrResult s2 =3D { }; =20 - if (get_phys_addr_lpae(env, &s2ptw, addr, MMU_DATA_LOAD, - false, &s2, fi)) { - goto fail; - } - ptw->out_phys =3D s2.f.phys_addr; - pte_attrs =3D s2.cacheattrs.attrs; - pte_secure =3D s2.f.attrs.secure; - } else { - /* Regime is physical. */ - ptw->out_phys =3D addr; - pte_attrs =3D 0; - pte_secure =3D is_secure; + if (get_phys_addr_with_struct(env, &s2ptw, addr, + MMU_DATA_LOAD, &s2, fi)) { + goto fail; } + ptw->out_phys =3D s2.f.phys_addr; + pte_attrs =3D s2.cacheattrs.attrs; + pte_secure =3D s2.f.attrs.secure; ptw->out_host =3D NULL; ptw->out_rw =3D false; } else { --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935724; cv=none; d=zohomail.com; s=zohoarc; b=a4v0EIBrNPb9K8aIEfl0cW/r217Pd29RQRCuXmOW2743T8Vc0T6tt8PXxZE7v+0EU1zi6jh8/PHxGezc9NO00wNlxOMikhLzbePcoP+ENUbQ8cOpVZiVAey8rLAZlfnUaaGQbG+8zqzSmhfTBiWOarZhRMpfF9T+3SwhgK6g4Dg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935724; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BVEetkVG320ZxIQr9yDM+qYom+RuVqLVN5o0T0FCipE=; b=EOmkr921p4XsOFHgTnnMaQw5hw42Buf8gq41C5KfZALc7jT77k9+shue2QiGmy0udyKYjQt8MTBt2AtVdCZEFiNw8xSg3mjjqTIifdWv5jGiUG2LaQFVE5ffc9241S8fO+vAr3R22e1wrOHeM3Qc+YFtvmV12B15pOe0UD52uGA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935724263162.09544350883516; Mon, 20 Feb 2023 15:28:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYj-0004Sy-Fj; Mon, 20 Feb 2023 18:27:01 -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 1pUFYg-0004IC-3d for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:58 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYc-0000NW-TH for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:57 -0500 Received: by mail-pl1-x62e.google.com with SMTP id p1so1087727plg.7 for ; Mon, 20 Feb 2023 15:26:54 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:53 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BVEetkVG320ZxIQr9yDM+qYom+RuVqLVN5o0T0FCipE=; b=OW8KVE9sJMbB+drBXDgUajHsWhzA/EGZfNsi8UmVDZwIek6zhfldCnEmhcogxh8IaG 7wHHo7hQmh+HmFneIlIqtCzDpViXDzz+MXDBkapjOlIrdAjsFnv1k40Dt0TWTV/mrVHQ a/3ngITwO+idNWOv1yakpDwq3UEvGh/3kajqy+Aa4apd6v47nGN41sY2vIhuCyDFbHle vWhlx4GhG7AWtUHahTK59jGXV7oO1MF9660Hs/9SR6finiqwyGG+zgbN1Z8rUWYITv8O /egsoV/gxZ0m9vCx2EL4VAJgUqLW3TaZLYin6/4duS4/gK91JparqugLmbd8Vc3/hbvq A1VQ== 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 :subject:date:message-id:reply-to; bh=BVEetkVG320ZxIQr9yDM+qYom+RuVqLVN5o0T0FCipE=; b=ycZaMoK0sSQY2tnCe54i2mQuKn5aYiJ7YPDgJ3fqnNfkJJd1VmtOCNOZuqiiTGu7CQ aAUAa+6GGMRQOMrXGNJeX2WHQbEG1nJcZ56raLOl98XOxR7I+Mrwk05Og0di7a8xisiV aDiC0bL8ipJGT/D0FwVv9M3XzWvM/dlhPCwqV6D+3EQjBlCM1iWUkRSamSmAs/7roE0/ UL60StIrQZGrasp0pJG/jXiU1tT0ximuIVUdCDBPDzCjTgjH/j6ZhvgbJ5r41qj4TDhp 7klY5hehFxLW+3tks+Z3oMjCgc6wrvdm9hhjEoVPjIxfRxvub3R89BsYNQcnRPR6MVZ6 RaCg== X-Gm-Message-State: AO0yUKWx3gdZLfxK7bbcidFBTh0hIcmmj86O5qGkn3pc6VT5rUvoFgol p7AR2NSUVJxi4JzYyqU7MOPkMFEoImR26R/DZUo= X-Google-Smtp-Source: AK7set9w4QA01H2Z9WPfkldITox3xTIGNIO+HroJqRNmwuoyt5ELBFEtWhzoPa63aUFdUIqwFb8Wyg== X-Received: by 2002:a17:902:f546:b0:19a:8304:21eb with SMTP id h6-20020a170902f54600b0019a830421ebmr2215395plf.6.1676935614019; Mon, 20 Feb 2023 15:26:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 15/21] target/arm: Move s1_is_el0 into S1Translate Date: Mon, 20 Feb 2023 13:26:20 -1000 Message-Id: <20230220232626.429947-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935725994100009 Content-Type: text/plain; charset="utf-8" Instead of passing this to get_phys_addr_lpae, stash it in the S1Translate structure. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 6e980654be..d4027ce763 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -22,6 +22,12 @@ typedef struct S1Translate { ARMSecuritySpace in_space; bool in_secure; bool in_debug; + /* + * If this is stage 2 of a stage 1+2 page table walk, then this must + * be true if stage 1 is an EL0 access; otherwise this is ignored. + * Stage 2 is indicated by in_mmu_idx set to ARMMMUIdx_Stage2{,_S}. + */ + bool in_s1_is_el0; bool out_secure; bool out_rw; bool out_be; @@ -33,7 +39,7 @@ typedef struct S1Translate { =20 static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, uint64_t address, - MMUAccessType access_type, bool s1_is_el0, + MMUAccessType access_type, GetPhysAddrResult *result, ARMMMUFaultInfo = *fi) __attribute__((nonnull)); =20 @@ -1257,17 +1263,12 @@ static int check_s2_mmu_setup(ARMCPU *cpu, bool is_= aa64, uint64_t tcr, * @ptw: Current and next stage parameters for the walk. * @address: virtual address to get physical address for * @access_type: MMU_DATA_LOAD, MMU_DATA_STORE or MMU_INST_FETCH - * @s1_is_el0: if @ptw->in_mmu_idx is ARMMMUIdx_Stage2 - * (so this is a stage 2 page table walk), - * must be true if this is stage 2 of a stage 1+2 - * walk for an EL0 access. If @mmu_idx is anything else, - * @s1_is_el0 is ignored. * @result: set on translation success, * @fi: set to fault info if the translation fails */ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, uint64_t address, - MMUAccessType access_type, bool s1_is_el0, + MMUAccessType access_type, GetPhysAddrResult *result, ARMMMUFaultInfo = *fi) { ARMCPU *cpu =3D env_archcpu(env); @@ -1600,7 +1601,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Tr= anslate *ptw, result->f.prot =3D get_S2prot_noexecute(ap); } else { xn =3D extract64(attrs, 53, 2); - result->f.prot =3D get_S2prot(env, ap, xn, s1_is_el0); + result->f.prot =3D get_S2prot(env, ap, xn, ptw->in_s1_is_el0); } } else { int nse, ns =3D extract32(attrs, 5, 1); @@ -2822,7 +2823,6 @@ static bool get_phys_addr_twostage(CPUARMState *env, = S1Translate *ptw, bool ret, ipa_secure, s2walk_secure; ARMCacheAttrs cacheattrs1; ARMSecuritySpace ipa_space, s2walk_space; - bool is_el0; uint64_t hcr; =20 ret =3D get_phys_addr_with_struct(env, ptw, address, access_type, resu= lt, fi); @@ -2847,7 +2847,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, = S1Translate *ptw, s2walk_space =3D ipa_space; } =20 - is_el0 =3D ptw->in_mmu_idx =3D=3D ARMMMUIdx_Stage1_E0; + ptw->in_s1_is_el0 =3D ptw->in_mmu_idx =3D=3D ARMMMUIdx_Stage1_E0; ptw->in_mmu_idx =3D s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Sta= ge2; ptw->in_ptw_idx =3D arm_space_to_phys(s2walk_space); ptw->in_secure =3D s2walk_secure; @@ -2866,8 +2866,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, = S1Translate *ptw, ret =3D get_phys_addr_pmsav8(env, ipa, access_type, ptw->in_mmu_idx, is_secure, result, fi); } else { - ret =3D get_phys_addr_lpae(env, ptw, ipa, access_type, - is_el0, result, fi); + ret =3D get_phys_addr_lpae(env, ptw, ipa, access_type, result, fi); } fi->s2addr =3D ipa; =20 @@ -3043,8 +3042,7 @@ static bool get_phys_addr_with_struct(CPUARMState *en= v, S1Translate *ptw, } =20 if (regime_using_lpae_format(env, mmu_idx)) { - return get_phys_addr_lpae(env, ptw, address, access_type, false, - result, fi); + return get_phys_addr_lpae(env, ptw, address, access_type, result, = fi); } else if (arm_feature(env, ARM_FEATURE_V7) || regime_sctlr(env, mmu_idx) & SCTLR_XP) { return get_phys_addr_v6(env, ptw, address, access_type, result, fi= ); --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935723; cv=none; d=zohomail.com; s=zohoarc; b=VM4R4b3XvCnezXShAgKSZ0dfz3SRXeWtJu4hIMyHXAEgTA/1j1NQpTdOxwtsymH/nXnDae93aJ4t0qAHUslLWfmkaT3v7mw/Cryd1L5TVV9nfJZkDR7angh0IPfyQejVQNYnwGOyK5ELyjjpyGjuYCryXQcCBUeFRkUprndsQPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935723; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z+JHhydbaosxqUvfvn4Z1EbkvskX2ro+PNfi5dyuur8=; b=Sz1gJ8LdB1SC6VKXZpTkWZmsosMJMDpcWcgnNPjLOjGznluu/U/Xt4ExzXhhvtjvMW1ImVzi3ZiJR7Rd8Ox1ckRi6FUTk4DcYQjrkHARBoZ178hpUCGPYCUm6JxuJ4gMsr/gWGA3BNl7TcbN2n8RVexb8fLmcil3QZjiPZY637Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167693572311047.6614466720506; Mon, 20 Feb 2023 15:28:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYo-0004dF-W3; Mon, 20 Feb 2023 18:27:07 -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 1pUFYg-0004LJ-Fl for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:58 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYe-0000Ql-N4 for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:58 -0500 Received: by mail-pl1-x62e.google.com with SMTP id l15so4272588pls.1 for ; Mon, 20 Feb 2023 15:26:56 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:54 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z+JHhydbaosxqUvfvn4Z1EbkvskX2ro+PNfi5dyuur8=; b=iShDDGQEfJEYmQi1R7YjYxYit1A3Rd0HP10oApwqXWIITj9GEJk0CNj6Wyux5FP4Jk 6puaMKIZYhkpTNqtPCkvX0YixG0EimoV88DdhWyyxCX4BiaImsfES1NOo+6jbYcq+v7f eH+gFn/bk2n5JJ9ZejikUToKmX79XN3esNHuUi9Ay1WYlaRQYCEMnb1aj9oMom6Wca/c CxMdeJYRl9wzc+jmMdg4DZrIEQlqxTYPoVGU4Tx9kGyNyQ4p631O7buLgfL26PQ18DX+ yWMnq1GFk4n8a0UHIW5ZSKV972jY6qwQLk0zX2eaUs+yO3qgVM3u9wFosfM3eZnnkwS9 xD2A== 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 :subject:date:message-id:reply-to; bh=Z+JHhydbaosxqUvfvn4Z1EbkvskX2ro+PNfi5dyuur8=; b=0BzzZtRiYDj1S5QpyjMpI0BTKnsmNfoEMD3/m9/r1tRJCWJ97F3V9U13bb55s0ZFJQ F/Zr8phtwPnyqMtrCQW53nB950Ax37ytlbxhuwX051S4uGGraXamyHO+pzPD5SJijd8I Ks1dc1SEJ1LSJV8OTzaTlDxv5haWm0EG4P7u/Z2vN1XQ1IP8Bbvn4/+CjZgJNkRCJW1G Ki6VvmTk0mdHVdF7WqC40pXskSROInBsGaLLZCa/vqXZthWap4OLfZaxTeqQ2kdu/cHy FOLM+FmAhjxtmL4XmZzSCBq/AUFkX0pDN263Md/Te0kfgNwBXM9D+xvNUCiY5FceXzGl BVXw== X-Gm-Message-State: AO0yUKV2GF7fRXcIQ5+fHButIooAwsZ7ulYpsFm74uBzHvMY2FM1Rnd3 b/hL4+b1gZhhmeRYp+dtYvrPmUNsN6CDxHkc8Mw= X-Google-Smtp-Source: AK7set/DHfL5vjFYXCUZcKzpa9Ed/SoTibpEPRMUkX2CDk81MvHO60ZM3BzBFWL7Nm5n74ju6TgqRA== X-Received: by 2002:a17:903:110c:b0:199:3683:5410 with SMTP id n12-20020a170903110c00b0019936835410mr6148568plh.50.1676935615402; Mon, 20 Feb 2023 15:26:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 16/21] target/arm: Use get_phys_addr_with_struct for stage2 Date: Mon, 20 Feb 2023 13:26:21 -1000 Message-Id: <20230220232626.429947-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935724001100001 Content-Type: text/plain; charset="utf-8" This fixes a bug in which we failed to initialize the result attributes properly after the memset. Signed-off-by: Richard Henderson --- target/arm/ptw.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index d4027ce763..a797750f9b 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -37,12 +37,6 @@ typedef struct S1Translate { void *out_host; } S1Translate; =20 -static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, - uint64_t address, - MMUAccessType access_type, - GetPhysAddrResult *result, ARMMMUFaultInfo = *fi) - __attribute__((nonnull)); - static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, target_ulong address, MMUAccessType access_type, @@ -2862,12 +2856,7 @@ static bool get_phys_addr_twostage(CPUARMState *env,= S1Translate *ptw, cacheattrs1 =3D result->cacheattrs; memset(result, 0, sizeof(*result)); =20 - if (arm_feature(env, ARM_FEATURE_PMSA)) { - ret =3D get_phys_addr_pmsav8(env, ipa, access_type, - ptw->in_mmu_idx, is_secure, result, fi); - } else { - ret =3D get_phys_addr_lpae(env, ptw, ipa, access_type, result, fi); - } + ret =3D get_phys_addr_with_struct(env, ptw, ipa, access_type, result, = fi); fi->s2addr =3D ipa; =20 /* Combine the S1 and S2 perms. */ --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935755; cv=none; d=zohomail.com; s=zohoarc; b=b5NMaAwuZcrLjMkLrlV5+fcGo44vugPwXhhLe9CoPnCB4qnyb8Mi/7eWXU7q8w/CUVmjvoZ0xUDwy0zoGicJaRREycU+N1SZ2eMPygSrtMJkRouTKhhtGkzKhztyIW4brhuXbdp1OpKKQx4s18xg+TGHCmAdE/DyjOciauGp+us= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935755; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BdnIrBC/vjhypfMOEhRm01STyDVGWe2QDHvXiznUOKk=; b=in4IEtHRjVyuwCzqGZvHkTqg0tvvQtjUameHwjqTTQQ645FbQfQK27kKchKMNEVUm3vYsVKQVTSq7xq3QncYQuXWhBfuZPnJVAyaw5yM8d0/9tEJKiJHWD+yoXOpZwJPBtCuCyuBY6rr0rMoffT5tReSyl5UDzBxpPy6x0BfLPs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935755240619.1717627005216; Mon, 20 Feb 2023 15:29:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYp-0004eI-3j; Mon, 20 Feb 2023 18:27:07 -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 1pUFYh-0004P6-Cy for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:59 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYf-0000M3-Qk for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:59 -0500 Received: by mail-pj1-x102b.google.com with SMTP id pt11so3454283pjb.1 for ; Mon, 20 Feb 2023 15:26:57 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:56 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BdnIrBC/vjhypfMOEhRm01STyDVGWe2QDHvXiznUOKk=; b=TUOdBq8xbouISD67Tp0NvVaozs9Bhh6/loj1Byeww6gSDx3TKf4KT8/XkpqD+AMNTd eT2cc+p+ri/R1YCaaGWdbTJDkHzeeNc7RT4BCNXXf809f1VEeGq5EbjKeMQM2mJr12VK Z4FSa4NH5rcikVDpvGATz3KU7Rz8EbcHC37Q3TBIblxKO/H+UbRCPeM+3MIjW0F8UweS R2NkhLcxYODbpY99GUGX7rq+zGD2q5/z0ur8Icl1PTiBCnbOUrMlHHMpj7HhVGCtlI3m tBQrzz9pyNwuaQm1HMDzm72TNnc5q0xzDCMy2O/rnk0PiEiKoRFvMFhvHCzFHTg/lrNJ Xm0g== 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 :subject:date:message-id:reply-to; bh=BdnIrBC/vjhypfMOEhRm01STyDVGWe2QDHvXiznUOKk=; b=i4GFXfMsigZzHg/z36BVCC2XpDnvaD3ARRJhb6i3FeoAgP4OzFK0elrkEHdTu1HYoL x+kICsiFLqBCmWy+8HZ8D1Y7HfriBqpJ1V76UBfm/mfKjEhhgWstqUhmUMKKfKSmCmNP 3Ndpa5wRW+TKWbiR670v44cncVepxy4h9fCjXGvHdKqsx6Frg4mP/hH5pe1XDoUTsUlB tDzLBjRhseUrT3mqmaWBfXMNXO9tA+c69ZuUBjHH8BFHZFPhcBYc1gQ464hndCiFp5VW 199sQJPW8V3fT81/cy5UCuyMYEyPEsxFQOh93aOTF9BWBYPU/uQBaABuknxwgb2nMid9 kbKA== X-Gm-Message-State: AO0yUKVBxmE/VHkTpi7EkG1tpNQoNj6Gld+/xwjL+RWpxWshrjlVsPaE 2J9V0XlyioSVQl4+7w24k8vujFj5jjGRqJJys2M= X-Google-Smtp-Source: AK7set94qzNj2GEQdbBQLQFz2P5HaFHnVRExD36ys8Jy6H9mGkjB2VQdPqZ0sCTOou18+rVFXkyvjA== X-Received: by 2002:a17:903:32cf:b0:19a:b092:b31a with SMTP id i15-20020a17090332cf00b0019ab092b31amr2393748plr.8.1676935616792; Mon, 20 Feb 2023 15:26:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 17/21] target/arm: Add GPC syndrome Date: Mon, 20 Feb 2023 13:26:22 -1000 Message-Id: <20230220232626.429947-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935756105100001 Content-Type: text/plain; charset="utf-8" The function takes the fields as filled in by the Arm ARM pseudocode for TakeGPCException. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/syndrome.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/target/arm/syndrome.h b/target/arm/syndrome.h index d27d1bc31f..62254d0e51 100644 --- a/target/arm/syndrome.h +++ b/target/arm/syndrome.h @@ -50,6 +50,7 @@ enum arm_exception_class { EC_SVEACCESSTRAP =3D 0x19, EC_ERETTRAP =3D 0x1a, EC_SMETRAP =3D 0x1d, + EC_GPC =3D 0x1e, EC_INSNABORT =3D 0x20, EC_INSNABORT_SAME_EL =3D 0x21, EC_PCALIGNMENT =3D 0x22, @@ -247,6 +248,15 @@ static inline uint32_t syn_bxjtrap(int cv, int cond, i= nt rm) (cv << 24) | (cond << 20) | rm; } =20 +static inline uint32_t syn_gpc(int s2ptw, int ind, int gpcsc, + int cm, int s1ptw, int wnr, int fsc) +{ + /* TODO: FEAT_NV2 adds VNCR */ + return (EC_GPC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (s2ptw << 21) + | (ind << 20) | (gpcsc << 14) | (cm << 8) | (s1ptw << 7) + | (wnr << 6) | fsc; +} + static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int = fsc) { return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935638; cv=none; d=zohomail.com; s=zohoarc; b=Iyu22ku1e/BOxH+qOSyBTAV/oOzHfYdapIQ7zyx68aZFCE/Ydlq6iRfj6gsJUAF+PQ9acyxCfhzX66fvcIrk0XSgVOv1DmEFfhj5QxC4XHpECkGVvjdn+fZIUvdszybuFfd/FTGCAt3tOBtM0YM5a4jTrZazuMtU3hkzycVNlTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935638; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=P3y/FFraIBsrnZDMo6qHECYIBj1ugEm+zw6wnTUMfbE=; b=hy2i34sJeUKWMhq0fxNR+2aQ8NKo+gy+GgAS7+CU+IM5t8i9B0vx7b9uGu12qJuQpoYV627T3S3hrJeYxd1XE0sZQ+oicdtUEaxZ9EhnbVNUTDRK9F/4fUdD8NcIccfphg4yTlTDyCXNe9wunSaA1qJvdO4bGnmA4WBQSSgKzqA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935638830768.9025875731755; Mon, 20 Feb 2023 15:27:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYn-0004XP-CS; Mon, 20 Feb 2023 18:27:05 -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 1pUFYj-0004T0-7A for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:27:01 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYh-0000Qk-7U for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:27:00 -0500 Received: by mail-pj1-x102e.google.com with SMTP id ei9-20020a17090ae54900b002349a303ca5so2877639pjb.4 for ; Mon, 20 Feb 2023 15:26:58 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:57 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P3y/FFraIBsrnZDMo6qHECYIBj1ugEm+zw6wnTUMfbE=; b=mxQDkBOfFwdPkteMkuHJBNcH5ZhRHkLd6u/0Sa34cJsBW4eJApwzGrcV5pHqC0FWsy Nuxvkvd/5T4ETncOVzCMXNEsHG/EuacIkWjZ6Vjjy5wKz9EYDj0KJmhdwnedhEJlLLf2 RhecQwZ4RdKkI4hwZKBfiAYhoyTFZzYs5WBBCg2ocCPkg6BbNu9LurrGpuXjv3Ix+pMh B+iaz+51fhxPTPBVufpYDugvQHjPzQJ1YUdrs+Qiz3WFtn/W+R9Rqdi2dobrOU4lvl1f P9wOnlra4B5GJa6tlmiz+o49zpOnZG3WbqGKbU/xywhmMCTaH5xzxWE9fvDTiClsBL0T Rhew== 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 :subject:date:message-id:reply-to; bh=P3y/FFraIBsrnZDMo6qHECYIBj1ugEm+zw6wnTUMfbE=; b=q1014vV7/6xcfvoGyVZCbjkKn1sQP2cKsDuFzTON2jHg7Bo/rKmDKqHeh3OMFB1x2p IaiHpAMqxifViN1YhzuherFPGwWdecnJZDATby2OqafbInIT4TqtjKGp+IyGKvrNvPa2 vSQlsRoA7EBjcaDzt5v25W9GMvY4pelJWJ2t83Q5kSw6W/+ZGxnmd36L8Gh2k4w8aXYN UMxkJtXPDDdbg2wAbq18IpR0f8u96Kf2ZnnKKzgg7453skZ2ZMn09p6T67RStczrViPd +Mj4kSQt5ceRCjLcX0U1zdCgM45favn7yWIBpCoxOL3uDXr4zXSpnZZsnwQKvYUbPUaG KCgw== X-Gm-Message-State: AO0yUKXYZNzCXmYchRwigDFnPL8Olay0WwISoJKxaHsBHgnGDw/2v90t RXyzBMlXBjKZSn7rQ9eyuHsedYpU9WuMSrvYT0E= X-Google-Smtp-Source: AK7set/w3v0e+FBnlXj5rqZSoCglWR5MEUKKmFBhm8Mhp2/R7l0n1OruelWFYOzRCe9PmGfbXTlZXQ== X-Received: by 2002:a17:903:11d1:b0:19b:3b4:3af5 with SMTP id q17-20020a17090311d100b0019b03b43af5mr5917488plh.34.1676935618273; Mon, 20 Feb 2023 15:26:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 18/21] target/arm: Implement GPC exceptions Date: Mon, 20 Feb 2023 13:26:23 -1000 Message-Id: <20230220232626.429947-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935639643100001 Content-Type: text/plain; charset="utf-8" Handle GPC Fault types in arm_deliver_fault, reporting as either a GPC exception at EL3, or falling through to insn or data aborts at various exception levels. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 1 + target/arm/internals.h | 27 ++++++++++++ target/arm/helper.c | 5 +++ target/arm/tlb_helper.c | 96 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 126 insertions(+), 3 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 4bafe8340e..faafb63520 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -57,6 +57,7 @@ #define EXCP_UNALIGNED 22 /* v7M UNALIGNED UsageFault */ #define EXCP_DIVBYZERO 23 /* v7M DIVBYZERO UsageFault */ #define EXCP_VSERR 24 +#define EXCP_GPC 25 /* v9 Granule Protection Check Fault */ /* NB: add new EXCP_ defines to the array in arm_log_exception() too */ =20 #define ARMV7M_EXCP_RESET 1 diff --git a/target/arm/internals.h b/target/arm/internals.h index 759b70c646..5e88649fea 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -352,14 +352,27 @@ typedef enum ARMFaultType { ARMFault_ICacheMaint, ARMFault_QEMU_NSCExec, /* v8M: NS executing in S&NSC memory */ ARMFault_QEMU_SFault, /* v8M: SecureFault INVTRAN, INVEP or AUVIOL */ + ARMFault_GPCFOnWalk, + ARMFault_GPCFOnOutput, } ARMFaultType; =20 +typedef enum ARMGPCF { + GPCF_None, + GPCF_AddressSize, + GPCF_Walk, + GPCF_EABT, + GPCF_Fail, +} ARMGPCF; + /** * ARMMMUFaultInfo: Information describing an ARM MMU Fault * @type: Type of fault + * @gpcf: Subtype of ARMFault_GPCFOn{Walk,Output}. * @level: Table walk level (for translation, access flag and permission f= aults) * @domain: Domain of the fault address (for non-LPAE CPUs only) * @s2addr: Address that caused a fault at stage 2 + * @paddr: physical address that caused a fault for gpc + * @paddr_space: physical address space that caused a fault for gpc * @stage2: True if we faulted at stage 2 * @s1ptw: True if we faulted at stage 2 while doing a stage 1 page-table = walk * @s1ns: True if we faulted on a non-secure IPA while in secure state @@ -368,7 +381,10 @@ typedef enum ARMFaultType { typedef struct ARMMMUFaultInfo ARMMMUFaultInfo; struct ARMMMUFaultInfo { ARMFaultType type; + ARMGPCF gpcf; target_ulong s2addr; + target_ulong paddr; + ARMSecuritySpace paddr_space; int level; int domain; bool stage2; @@ -542,6 +558,17 @@ static inline uint32_t arm_fi_to_lfsc(ARMMMUFaultInfo = *fi) case ARMFault_Exclusive: fsc =3D 0x35; break; + case ARMFault_GPCFOnWalk: + assert(fi->level >=3D -1 && fi->level <=3D 3); + if (fi->level < 0) { + fsc =3D 0b100011; + } else { + fsc =3D 0b100100 | fi->level; + } + break; + case ARMFault_GPCFOnOutput: + fsc =3D 0b101000; + break; default: /* Other faults can't occur in a context that requires a * long-format status code. diff --git a/target/arm/helper.c b/target/arm/helper.c index 13af812215..5dc3329f0c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10235,6 +10235,7 @@ void arm_log_exception(CPUState *cs) [EXCP_UNALIGNED] =3D "v7M UNALIGNED UsageFault", [EXCP_DIVBYZERO] =3D "v7M DIVBYZERO UsageFault", [EXCP_VSERR] =3D "Virtual SERR", + [EXCP_GPC] =3D "Granule Protection Check", }; =20 if (idx >=3D 0 && idx < ARRAY_SIZE(excnames)) { @@ -10963,6 +10964,10 @@ static void arm_cpu_do_interrupt_aarch64(CPUState = *cs) } =20 switch (cs->exception_index) { + case EXCP_GPC: + qemu_log_mask(CPU_LOG_INT, "...with MFAR 0x%" PRIx64 "\n", + env->cp15.mfar_el3); + /* fall through */ case EXCP_PREFETCH_ABORT: case EXCP_DATA_ABORT: /* diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c index 60abcbebe6..aa03d3f8dc 100644 --- a/target/arm/tlb_helper.c +++ b/target/arm/tlb_helper.c @@ -109,17 +109,106 @@ static uint32_t compute_fsr_fsc(CPUARMState *env, AR= MMMUFaultInfo *fi, return fsr; } =20 +static bool report_as_gpc_exception(ARMCPU *cpu, int current_el, + ARMMMUFaultInfo *fi) +{ + bool ret; + + switch (fi->gpcf) { + case GPCF_None: + return false; + case GPCF_AddressSize: + case GPCF_Walk: + case GPCF_EABT: + /* R_PYTGX: GPT faults are reported as GPC. */ + ret =3D true; + break; + case GPCF_Fail: + /* + * R_BLYPM: A GPF at EL3 is reported as insn or data abort. + * R_VBZMW, R_LXHQR: A GPF at EL[0-2] is reported as a GPC + * if SCR_EL3.GPF is set, otherwise an insn or data abort. + */ + ret =3D (cpu->env.cp15.scr_el3 & SCR_GPF) && current_el !=3D 3; + break; + default: + g_assert_not_reached(); + } + + assert(cpu_isar_feature(aa64_rme, cpu)); + assert(fi->type =3D=3D ARMFault_GPCFOnWalk || + fi->type =3D=3D ARMFault_GPCFOnOutput); + if (fi->gpcf =3D=3D GPCF_AddressSize) { + assert(fi->level =3D=3D 0); + } else { + assert(fi->level >=3D 0 && fi->level <=3D 1); + } + + return ret; +} + +static unsigned encode_gpcsc(ARMMMUFaultInfo *fi) +{ + static uint8_t const gpcsc[] =3D { + [GPCF_AddressSize] =3D 0b000000, + [GPCF_Walk] =3D 0b000100, + [GPCF_Fail] =3D 0b001100, + [GPCF_EABT] =3D 0b010100, + }; + + /* Note that we've validated fi->gpcf and fi->level above. */ + return gpcsc[fi->gpcf] | fi->level; +} + static G_NORETURN void arm_deliver_fault(ARMCPU *cpu, vaddr addr, MMUAccessType access_type, int mmu_idx, ARMMMUFaultInfo *fi) { CPUARMState *env =3D &cpu->env; - int target_el; + int target_el =3D exception_target_el(env); + int current_el =3D arm_current_el(env); bool same_el; uint32_t syn, exc, fsr, fsc; =20 - target_el =3D exception_target_el(env); + if (report_as_gpc_exception(cpu, current_el, fi)) { + target_el =3D 3; + + fsr =3D compute_fsr_fsc(env, fi, target_el, mmu_idx, &fsc); + + syn =3D syn_gpc(fi->stage2 && fi->type =3D=3D ARMFault_GPCFOnWalk, + access_type =3D=3D MMU_INST_FETCH, + encode_gpcsc(fi), 0, fi->s1ptw, + access_type =3D=3D MMU_DATA_STORE, fsc); + + env->cp15.mfar_el3 =3D fi->paddr; + switch (fi->paddr_space) { + case ARMSS_Secure: + break; + case ARMSS_NonSecure: + env->cp15.mfar_el3 |=3D R_MFAR_NS_MASK; + break; + case ARMSS_Root: + env->cp15.mfar_el3 |=3D R_MFAR_NSE_MASK; + break; + case ARMSS_Realm: + env->cp15.mfar_el3 |=3D R_MFAR_NSE_MASK | R_MFAR_NS_MASK; + break; + default: + g_assert_not_reached(); + } + + exc =3D EXCP_GPC; + goto do_raise; + } + + /* If SCR_EL3.GPF is unset, GPF may still be routed to EL2. */ + if (fi->gpcf =3D=3D GPCF_Fail && target_el < 2) { + if (arm_hcr_el2_eff(env) & HCR_GPF) { + target_el =3D 2; + } + } + if (fi->stage2) { target_el =3D 2; env->cp15.hpfar_el2 =3D extract64(fi->s2addr, 12, 47) << 4; @@ -127,8 +216,8 @@ void arm_deliver_fault(ARMCPU *cpu, vaddr addr, env->cp15.hpfar_el2 |=3D HPFAR_NS; } } - same_el =3D (arm_current_el(env) =3D=3D target_el); =20 + same_el =3D current_el =3D=3D target_el; fsr =3D compute_fsr_fsc(env, fi, target_el, mmu_idx, &fsc); =20 if (access_type =3D=3D MMU_INST_FETCH) { @@ -146,6 +235,7 @@ void arm_deliver_fault(ARMCPU *cpu, vaddr addr, exc =3D EXCP_DATA_ABORT; } =20 + do_raise: env->exception.vaddress =3D addr; env->exception.fsr =3D fsr; raise_exception(env, exc, syn, target_el); --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935778; cv=none; d=zohomail.com; s=zohoarc; b=Kw5iDlCguqGxaNxbPaWf3kZ4/yFuFPRT5rEdaxpNASlHZlqqKbsP1qjIYOcjOHYRWfXRAejlmUhjZiD6baV8MOS/TowgZdu/2p8/D7rKjw3pt7iluQ4E+CZ7FgeyLVP7IWMi0xiW3KzbTwkHgtYNK+eZ2orMgBMVK0FWAT2QkMU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935778; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CB7v28W7W1Dv5HV9sB7O4wNr8EzlcB/4NWcFaAYvGQM=; b=SZFaMceUkn1UJxZMVN6Te1LrrH3ewLCZJs74OxJmCJSDujiAaWPAAx/U60elrfKPeDddECnKAG8J/7skiI4qh36p016oCTV5vGUwLQTpebchV6wzJr605m+WGdZTZuc1SHuM8SSeUDgRE6ZgEu6xO5O/HcADxLPnc2G2g9hI250= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935778307504.48505838155313; Mon, 20 Feb 2023 15:29:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYp-0004f7-AU; Mon, 20 Feb 2023 18:27:07 -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 1pUFYl-0004WZ-5r for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:27:03 -0500 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYj-0000Sr-0s for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:27:02 -0500 Received: by mail-pj1-x1043.google.com with SMTP id co23-20020a17090afe9700b002341fadc370so2883489pjb.1 for ; Mon, 20 Feb 2023 15:27:00 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:59 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CB7v28W7W1Dv5HV9sB7O4wNr8EzlcB/4NWcFaAYvGQM=; b=CnnaTUXhBcptOtQXod9rLLmTGyY7/tB7jN6obmasYkKL/qxH6/YGXuf0D+8yk0Fco0 AyYgNKgKFIdjqFTvCOz2lSv/EWwGBpw/aUIaIo7FQEPifutOZDgZfkltDdUSbg1Z/jIW itb/Zg/QFCDKYiOmYHghTi3lkDPsfu8BsdE3tpCkIn8Nwzyao1vQt5AqMGYXgI8e2GEs yJV6KIS+RUXfoGNzv0mAHZact4gbK0UEQDE6h2WuyYutO4KCYfJ5WdSl0ya5jkw+B5FN NmAzpRgXMyvXFxYD2EXqu96OK2ZeKGthc/OU+SYag/GED3zQtdLKa1ZxcBxKY016wWxQ VXnQ== 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 :subject:date:message-id:reply-to; bh=CB7v28W7W1Dv5HV9sB7O4wNr8EzlcB/4NWcFaAYvGQM=; b=0OTUnClj8q26wfl2cx6ebhAXT0zNEfCfrgWF28rPJj+X6H94/Ik4i6pa0Kx6MkphK2 jXH4U/1BjrVwwHq+yojIdHt/YWifVU2+b49fhpqiOpfkgFBaH0ELIs/Du+8vqZ07yVEi qwJI6e2mvSu77PRwTDxgYHn2662bWb+v+D3cSR1kM7347VtUNC0+U4IHLjmktx2G3fpw QQ0mqRiT8DtlbFXqlcYyYqshYkfVUNcwO3OqSN/xs4jYJmnTRDoabumcUabtlQBvHSmS 6cZfgMIj4avxbdBOpX/AIdSxl1Mrek4CEZCiCtZGwi4oI5btNd5U1mRe5xy3jIxvq70d B9GQ== X-Gm-Message-State: AO0yUKVspiVQoLOtjyP8ce5xWUKi8QhpMie4njtkPEPftJRcJsHdmCf0 yChivYtv6N5gI93Q8VpsRCUn2Sw83RZZSfLEnaZ7MA== X-Google-Smtp-Source: AK7set8RRZSlCUKV6YxAchVKQeL+XggwREu7v8vcM3NoLnZMSvNiqG2AICtGpF24dWKy0n20+5Ce0Q== X-Received: by 2002:a17:902:d48c:b0:19a:841f:57 with SMTP id c12-20020a170902d48c00b0019a841f0057mr5135948plg.27.1676935619715; Mon, 20 Feb 2023 15:26:59 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v2 19/21] target/arm: Implement the granule protection check Date: Mon, 20 Feb 2023 13:26:24 -1000 Message-Id: <20230220232626.429947-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935780399100003 Content-Type: text/plain; charset="utf-8" Place the check at the end of get_phys_addr_with_struct, so that we check all physical results. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 246 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 228 insertions(+), 18 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index a797750f9b..b2f55f7f66 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -37,12 +37,11 @@ typedef struct S1Translate { void *out_host; } S1Translate; =20 -static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, - target_ulong address, - MMUAccessType access_type, - GetPhysAddrResult *result, - ARMMMUFaultInfo *fi) - __attribute__((nonnull)); +static bool get_phys_addr_nogpc(CPUARMState *env, S1Translate *ptw, + target_ulong address, + MMUAccessType access_type, + GetPhysAddrResult *result, + ARMMMUFaultInfo *fi); =20 /* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. = */ static const uint8_t pamax_map[] =3D { @@ -198,6 +197,197 @@ static bool regime_translation_disabled(CPUARMState *= env, ARMMMUIdx mmu_idx, return (regime_sctlr(env, mmu_idx) & SCTLR_M) =3D=3D 0; } =20 +static bool granule_protection_check(CPUARMState *env, uint64_t paddress, + ARMSecuritySpace pspace, + ARMMMUFaultInfo *fi) +{ + MemTxAttrs attrs =3D { + .secure =3D true, + .space =3D ARMSS_Root, + }; + ARMCPU *cpu =3D env_archcpu(env); + uint64_t gpccr =3D env->cp15.gpccr_el3; + unsigned pps, pgs, l0gptsz, level =3D 0; + uint64_t tableaddr, pps_mask, align, entry, index; + AddressSpace *as; + MemTxResult result; + int gpi; + + if (!FIELD_EX64(gpccr, GPCCR, GPC)) { + return true; + } + + /* + * GPC Priority 1 (R_GMGRR): + * R_JWCSM: If the configuration of GPCCR_EL3 is invalid, + * the access fails as GPT walk fault at level 0. + */ + + /* + * Configuration of PPS to a value exceeding the implemented + * physical address size is invalid. + */ + pps =3D FIELD_EX64(gpccr, GPCCR, PPS); + if (pps > FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE)) { + goto fault_walk; + } + pps =3D pamax_map[pps]; + pps_mask =3D MAKE_64BIT_MASK(0, pps); + + switch (FIELD_EX64(gpccr, GPCCR, SH)) { + case 0b10: /* outer shareable */ + break; + case 0b00: /* non-shareable */ + case 0b11: /* inner shareable */ + /* Inner and Outer non-cacheable requires Outer shareable. */ + if (FIELD_EX64(gpccr, GPCCR, ORGN) =3D=3D 0 && + FIELD_EX64(gpccr, GPCCR, IRGN) =3D=3D 0) { + goto fault_walk; + } + break; + default: /* reserved */ + goto fault_walk; + } + + switch (FIELD_EX64(gpccr, GPCCR, PGS)) { + case 0b00: /* 4KB */ + pgs =3D 12; + break; + case 0b01: /* 64KB */ + pgs =3D 16; + break; + case 0b10: /* 16KB */ + pgs =3D 14; + break; + default: /* reserved */ + goto fault_walk; + } + + /* Note this field is read-only and fixed at reset. */ + l0gptsz =3D 30 + FIELD_EX64(gpccr, GPCCR, L0GPTSZ); + + /* + * GPC Priority 2: Secure, Realm or Root address exceeds PPS. + * R_CPDSB: A NonSecure physical address input exceeding PPS + * does not experience any fault. + */ + if (paddress & ~pps_mask) { + if (pspace =3D=3D ARMSS_NonSecure) { + return true; + } + goto fault_size; + } + + /* GPC Priority 3: the base address of GPTBR_EL3 exceeds PPS. */ + tableaddr =3D env->cp15.gptbr_el3 << 12; + if (tableaddr & ~pps_mask) { + goto fault_size; + } + + /* + * BADDR is aligned per a function of PPS and L0GPTSZ. + * These bits of GPTBR_EL3 are RES0, but are not a configuration error, + * unlike the RES0 bits of the GPT entries (R_XNKFZ). + */ + align =3D MAX(pps - l0gptsz + 3, 12); + align =3D MAKE_64BIT_MASK(0, align); + tableaddr &=3D ~align; + + as =3D arm_addressspace(env_cpu(env), attrs); + + /* Level 0 lookup. */ + index =3D extract64(paddress, l0gptsz, pps - l0gptsz); + tableaddr +=3D index * 8; + entry =3D address_space_ldq_le(as, tableaddr, attrs, &result); + if (result !=3D MEMTX_OK) { + goto fault_eabt; + } + + switch (extract32(entry, 0, 4)) { + case 1: /* block descriptor */ + if (entry >> 8) { + goto fault_walk; /* RES0 bits not 0 */ + } + gpi =3D extract32(entry, 4, 4); + goto found; + case 3: /* table descriptor */ + tableaddr =3D entry & ~0xf; + align =3D MAX(l0gptsz - pgs - 1, 12); + align =3D MAKE_64BIT_MASK(0, align); + if (tableaddr & (~pps_mask | align)) { + goto fault_walk; /* RES0 bits not 0 */ + } + break; + default: /* invalid */ + goto fault_walk; + } + + /* Level 1 lookup */ + level =3D 1; + index =3D extract64(paddress, pgs + 4, l0gptsz - pgs - 4); + tableaddr +=3D index * 8; + entry =3D address_space_ldq_le(as, tableaddr, attrs, &result); + if (result !=3D MEMTX_OK) { + goto fault_eabt; + } + + switch (extract32(entry, 0, 4)) { + case 1: /* contiguous descriptor */ + if (entry >> 10) { + goto fault_walk; /* RES0 bits not 0 */ + } + /* + * Because the softmmu tlb only works on units of TARGET_PAGE_SIZE, + * and because we cannot invalidate by pa, and thus will always + * flush entire tlbs, we don't actually care about the range here + * and can simply extract the GPI as the result. + */ + if (extract32(entry, 8, 2) =3D=3D 0) { + goto fault_walk; /* reserved contig */ + } + gpi =3D extract32(entry, 4, 4); + break; + default: + index =3D extract64(paddress, pgs, 4); + gpi =3D extract64(entry, index * 4, 4); + break; + } + + found: + switch (gpi) { + case 0b0000: /* no access */ + break; + case 0b1111: /* all access */ + return true; + case 0b1000: + case 0b1001: + case 0b1010: + case 0b1011: + if (pspace =3D=3D (gpi & 3)) { + return true; + } + break; + default: + goto fault_walk; /* reserved */ + } + + fi->gpcf =3D GPCF_Fail; + goto fault_common; + fault_eabt: + fi->gpcf =3D GPCF_EABT; + goto fault_common; + fault_size: + fi->gpcf =3D GPCF_AddressSize; + goto fault_common; + fault_walk: + fi->gpcf =3D GPCF_Walk; + fault_common: + fi->level =3D level; + fi->paddr =3D paddress; + fi->paddr_space =3D pspace; + return false; +} + static bool S2_attrs_are_device(uint64_t hcr, uint8_t attrs) { /* @@ -243,10 +433,15 @@ static bool S1_ptw_translate(CPUARMState *env, S1Tran= slate *ptw, }; GetPhysAddrResult s2 =3D { }; =20 - if (get_phys_addr_with_struct(env, &s2ptw, addr, - MMU_DATA_LOAD, &s2, fi)) { + if (get_phys_addr_nogpc(env, &s2ptw, addr, MMU_DATA_LOAD, &s2, fi)= ) { goto fail; } + if (!granule_protection_check(env, s2.f.phys_addr, + s2.f.attrs.space, fi)) { + fi->type =3D ARMFault_GPCFOnWalk; + goto fail; + } + ptw->out_phys =3D s2.f.phys_addr; pte_attrs =3D s2.cacheattrs.attrs; pte_secure =3D s2.f.attrs.secure; @@ -2732,7 +2927,7 @@ static bool get_phys_addr_disabled(CPUARMState *env, = target_ulong address, ARMMMUFaultInfo *fi) { uint8_t memattr =3D 0x00; /* Device nGnRnE */ - uint8_t shareability =3D 0; /* non-sharable */ + uint8_t shareability =3D 0; /* non-shareable */ int r_el; =20 switch (mmu_idx) { @@ -2791,7 +2986,7 @@ static bool get_phys_addr_disabled(CPUARMState *env, = target_ulong address, } else { memattr =3D 0x44; /* Normal, NC, No */ } - shareability =3D 2; /* outer sharable */ + shareability =3D 2; /* outer shareable */ } result->cacheattrs.is_s2_format =3D false; break; @@ -2819,7 +3014,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, = S1Translate *ptw, ARMSecuritySpace ipa_space, s2walk_space; uint64_t hcr; =20 - ret =3D get_phys_addr_with_struct(env, ptw, address, access_type, resu= lt, fi); + ret =3D get_phys_addr_nogpc(env, ptw, address, access_type, result, fi= ); =20 /* If S1 fails, return early. */ if (ret) { @@ -2856,7 +3051,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, = S1Translate *ptw, cacheattrs1 =3D result->cacheattrs; memset(result, 0, sizeof(*result)); =20 - ret =3D get_phys_addr_with_struct(env, ptw, ipa, access_type, result, = fi); + ret =3D get_phys_addr_nogpc(env, ptw, ipa, access_type, result, fi); fi->s2addr =3D ipa; =20 /* Combine the S1 and S2 perms. */ @@ -2916,7 +3111,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, = S1Translate *ptw, return false; } =20 -static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, +static bool get_phys_addr_nogpc(CPUARMState *env, S1Translate *ptw, target_ulong address, MMUAccessType access_type, GetPhysAddrResult *result, @@ -3040,6 +3235,23 @@ static bool get_phys_addr_with_struct(CPUARMState *e= nv, S1Translate *ptw, } } =20 +static bool get_phys_addr_gpc(CPUARMState *env, S1Translate *ptw, + target_ulong address, + MMUAccessType access_type, + GetPhysAddrResult *result, + ARMMMUFaultInfo *fi) +{ + if (get_phys_addr_nogpc(env, ptw, address, access_type, result, fi)) { + return true; + } + if (!granule_protection_check(env, result->f.phys_addr, + result->f.attrs.space, fi)) { + fi->type =3D ARMFault_GPCFOnOutput; + return true; + } + return false; +} + bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, MMUAccessType access_type, ARMMMUIdx mmu_id= x, bool is_secure, GetPhysAddrResult *result, @@ -3050,8 +3262,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, targ= et_ulong address, .in_secure =3D is_secure, .in_space =3D arm_secure_to_space(is_secure), }; - return get_phys_addr_with_struct(env, &ptw, address, access_type, - result, fi); + return get_phys_addr_gpc(env, &ptw, address, access_type, result, fi); } =20 bool get_phys_addr(CPUARMState *env, target_ulong address, @@ -3121,8 +3332,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong add= ress, =20 ptw.in_space =3D ss; ptw.in_secure =3D arm_space_is_secure(ss); - return get_phys_addr_with_struct(env, &ptw, address, access_type, - result, fi); + return get_phys_addr_gpc(env, &ptw, address, access_type, result, fi); } =20 hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, @@ -3141,7 +3351,7 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs= , vaddr addr, ARMMMUFaultInfo fi =3D {}; bool ret; =20 - ret =3D get_phys_addr_with_struct(env, &ptw, addr, MMU_DATA_LOAD, &res= , &fi); + ret =3D get_phys_addr_gpc(env, &ptw, addr, MMU_DATA_LOAD, &res, &fi); *attrs =3D res.f.attrs; =20 if (ret) { --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935784; cv=none; d=zohomail.com; s=zohoarc; b=ILGT6wzmHkxytRXP3Pe8UFi33IsHAnHAxmwW3zfsw3YjNgL2EWP8pdZNP/1VgFj5nuG4F6Ea8kUF1bcxEwJdyhzDyG7baY4uQgczIbPmt9bG/YyvsQ4+KqPKSxP9puudygHx+MkznWqSz2IvkxcNizi234N3kNXkSVyeXeZiz3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935784; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/Ut/aS2oezKic9UZ9DAK+e9x8VNxmPUkA0viJdZ3AGc=; b=UQSfqiqta7PlTGfJxL4Pv+nFxp6TD/Z9eZShryRg3xGcF1/53JCeasW/1eqPxNBwjcR2YNBAU0EHGSirc7DwODwDqEY6iy2j4ny10cP35HVIhUETTAr8J+//FKu4xRrnaeDuyFyw7JS3YzOZMFdgjm5nHCKqTjUWEWdLwN4O508= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935784613173.3181156142922; Mon, 20 Feb 2023 15:29:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYs-0004oG-FX; Mon, 20 Feb 2023 18:27:10 -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 1pUFYm-0004XW-Sf for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:27:05 -0500 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYl-0000TE-8Q for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:27:04 -0500 Received: by mail-pj1-x1044.google.com with SMTP id nt5-20020a17090b248500b00237161e33f4so1010286pjb.4 for ; Mon, 20 Feb 2023 15:27:02 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:27:01 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/Ut/aS2oezKic9UZ9DAK+e9x8VNxmPUkA0viJdZ3AGc=; b=GhqdHjbrt2izcd84632/7HzZ/sVbJWMYyIOeUcjyL8xy8c7HZzFlH8ta323uZjYDZo gXvumDAmYks8aeypQrvrHTFIYKYUOzqmE+VJZd0fk20foX5qK9n6ShZJijB7I1fGXVAM a4QV/bX+kRZi0Ak5Dj1kNuPieD74OSiHjFFZwRcxGhKfVS7f8jPRDdZfuEMvSNp6c89R ymkHyyPngC3JM2yBJyRHI21tFx5e063YklRuGWxdfBi44/PiN3gTIlUUqn06QmISh8RM Ff1eaPESw+r+VyUAfkZ72aNc3cNSr2yW8iQjdMgY+1VuT5VceREwR2scRyQ7qJWWHixg r/eA== 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 :subject:date:message-id:reply-to; bh=/Ut/aS2oezKic9UZ9DAK+e9x8VNxmPUkA0viJdZ3AGc=; b=lP5JDXv241aA8yJhCPRlgojp7013x9K6XROOZZmF56q0DtQzm/sIAg/j9rRglwDgdO 6o0QTjsAAx90v0nBy+oc+vbUwLg4QPZHaof2nWyU5YjEt5NCk+xUPnXUC5Vj3moi8QgA s14NDKQIasJITlqcTv8sUTAd+0Oy8H7yqOdgCwXR5VX9DXprp+MCVCbIMfHdJMX1C+Sn yxl91mrf7sU5mLDKgTnzSWvqyr5Q7Un3aejEGzIQtThjOxKrpE4NipQ6DE9SSJfR4Osw YY4wvCa+RI/kkn0mvKcbDnxxUvI5OJin2VDv8cgELHPvaYegCl2j9xznjYVZmmj/INhx G19Q== X-Gm-Message-State: AO0yUKVmJTShHAlekYO7fl93n7u+h80iBVnBEz2X3lFXE4Cs4tfBaJlP pZspWGZ/tYROfbJ4+6RlDhYEPuvR50DPiWAMWt6T3w== X-Google-Smtp-Source: AK7set8l/I3OllVgHzv/KfcGMwJjZYwt2LTqa2qG2doE3pDiOHQvGYfKYouP1mirI5Vb1Mr3AIVhmQ== X-Received: by 2002:a17:902:ea07:b0:199:33ff:918a with SMTP id s7-20020a170902ea0700b0019933ff918amr4216964plg.21.1676935621746; Mon, 20 Feb 2023 15:27:01 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [NOTFORMERGE PATCH v2 20/21] target/arm: Enable RME for -cpu max Date: Mon, 20 Feb 2023 13:26:25 -1000 Message-Id: <20230220232626.429947-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1044.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935786282100005 Content-Type: text/plain; charset="utf-8" Add a cpu property to set GPCCR_EL3.L0GPTSZ, for testing various possible configurations. Signed-off-by: Richard Henderson --- target/arm/cpu64.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 4066950da1..70c173ee3d 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -672,6 +672,40 @@ void arm_cpu_lpa2_finalize(ARMCPU *cpu, Error **errp) cpu->isar.id_aa64mmfr0 =3D t; } =20 +static void cpu_max_set_l0gptsz(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + ARMCPU *cpu =3D ARM_CPU(obj); + uint32_t value; + + if (!visit_type_uint32(v, name, &value, errp)) { + return; + } + + /* Encode the value for the GPCCR_EL3 field. */ + switch (value) { + case 30: + case 34: + case 36: + case 39: + cpu->reset_l0gptsz =3D value - 30; + break; + default: + error_setg(errp, "invalid value for l0gptsz"); + error_append_hint(errp, "valid values are 30, 34, 36, 39\n"); + break; + } +} + +static void cpu_max_get_l0gptsz(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + ARMCPU *cpu =3D ARM_CPU(obj); + uint32_t value =3D cpu->reset_l0gptsz + 30; + + visit_type_uint32(v, name, &value, errp); +} + static void aarch64_a57_initfn(Object *obj) { ARMCPU *cpu =3D ARM_CPU(obj); @@ -1200,6 +1234,7 @@ static void aarch64_max_initfn(Object *obj) t =3D FIELD_DP64(t, ID_AA64PFR0, SVE, 1); t =3D FIELD_DP64(t, ID_AA64PFR0, SEL2, 1); /* FEAT_SEL2 */ t =3D FIELD_DP64(t, ID_AA64PFR0, DIT, 1); /* FEAT_DIT */ + t =3D FIELD_DP64(t, ID_AA64PFR0, RME, 1); /* FEAT_RME */ t =3D FIELD_DP64(t, ID_AA64PFR0, CSV2, 2); /* FEAT_CSV2_2 */ t =3D FIELD_DP64(t, ID_AA64PFR0, CSV3, 1); /* FEAT_CSV3 */ cpu->isar.id_aa64pfr0 =3D t; @@ -1301,6 +1336,8 @@ static void aarch64_max_initfn(Object *obj) object_property_add(obj, "sve-max-vq", "uint32", cpu_max_get_sve_max_v= q, cpu_max_set_sve_max_vq, NULL, NULL); qdev_property_add_static(DEVICE(obj), &arm_cpu_lpa2_property); + object_property_add(obj, "l0gptsz", "uint32", cpu_max_get_l0gptsz, + cpu_max_set_l0gptsz, NULL, NULL); } =20 static const ARMCPUInfo aarch64_cpus[] =3D { --=20 2.34.1 From nobody Wed May 15 02:40:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1676935665; cv=none; d=zohomail.com; s=zohoarc; b=nOdK+ayrw5oTC1EUO+PPQ3XwXb+HhNJ+UrEK5iMquzDcesNc30k87uyGaTKXbsn7I7+ZX9lziKa9U9YOrH5EL1SHwYY3Ge1V+WqT/fR/06m8AzPm8ZjHKhSfx37dY1GYAVh+KlkdtfnQRJzDtXLapQ5BIJK1TQ2I376ysmBg+CI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676935665; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=H9Qr7wA8wSIkfPgh/j+3hKBpjrPyoBLV3ksLdpb2kIs=; b=lcVZrqLN8ank+eKUTP9K4jdREPM1RukXx/oMlYB8YaS/NletSaRBoIZgMJpKd1OD7zXoFBewFa7rbmyoQyoLUP4T4l4kV9JWqRVGZ8sEqs7rdo8u/EKS5pTYNeq8aEshqZu9j/29ijA4UGwm2u6106FsPCZNZ5fkTwCoqs+yZSI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676935665348264.574245999631; Mon, 20 Feb 2023 15:27:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUFYr-0004if-7t; Mon, 20 Feb 2023 18:27:09 -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 1pUFYo-0004bz-1l for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:27:06 -0500 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYm-0000QK-1G for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:27:05 -0500 Received: by mail-pj1-x1034.google.com with SMTP id v3-20020a17090a6b0300b002341a2656e5so2796166pjj.1 for ; Mon, 20 Feb 2023 15:27:03 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:27:02 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H9Qr7wA8wSIkfPgh/j+3hKBpjrPyoBLV3ksLdpb2kIs=; b=Cr7nFj4SILcFDKj/Sxrao5rEXlPsCryfOXCDlh+Nf1jQ4Sxl300qNIafsVBRnM25Fk D/A+8heOpnJxYc88c8ntJRleQ457TPRKotefEojkvIm8nXTdqAitoFjgd+5XCVzwD7ad M1ccXMHwKuKRKRUZktgLABKUqg5mhRYNpWl6e//ZB4IEz4nYIgEWq4QBSc8WyI0fTQ5i KyVEw0v63kMzUAeamE6x+4WnTHXZPyFmE303IUUnQRTxWRj8Utcl6w0FIudRCgTKBaoy TTWDTxukPBJFtz9M2yxoR73YUM5LRqnblk3AeyrwPh+YjwLWUITFFPz37jdwU3t/arYh v/Aw== 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 :subject:date:message-id:reply-to; bh=H9Qr7wA8wSIkfPgh/j+3hKBpjrPyoBLV3ksLdpb2kIs=; b=afejGhz+hRHU8HyEXPJnRKtgygquXQ3ZSlffz64GQGt64fUEGQmB+MNx5Mf4zOP+xy hFAM7nd0qwq2CKRl4PHuzEVD4tzDnJiU4ZILM/IpDPZgNaJ6SjXhDHxG78F9fUPt60q7 0WaW4DsB2NsPMd7/KvQrQMfD9YA9dvDgNc6A77SSvPlsk2DKuJ05NOI1a9ktwbLZjXgu 3qtDrfHjfkMKR32JY9X/WLWKKl9o6fNRFovNeJOx3hdh6O8MYQEPaPLwWTXhq0xtlFi9 g4fiweCdeBplKup4TypPnH54AN8m8AUJxxmCPVKm5XxD+xI5BTwRHTL/Y+7BWRf05VNo oihA== X-Gm-Message-State: AO0yUKV6bQHAd88giGDISVuesKadteMk0RiJ5sILLcy6lOCYc30VpUlm ShOX/vR0AfchkG3hg8Gzbh7qojcX57QpeVHVghQ= X-Google-Smtp-Source: AK7set/+5BuffwV81xNHv8WTk6pDHlNrrQ78RZ0T9WHpNc5/Kanp6xWQMx0rW0mB018AkQ/mEzEEBw== X-Received: by 2002:a17:902:f544:b0:196:6577:5a96 with SMTP id h4-20020a170902f54400b0019665775a96mr5634257plf.30.1676935623209; Mon, 20 Feb 2023 15:27:03 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [NOTFORMERGE PATCH v2 21/21] hw/arm/virt: Add some memory for Realm Management Monitor Date: Mon, 20 Feb 2023 13:26:26 -1000 Message-Id: <20230220232626.429947-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1676935665733100001 Content-Type: text/plain; charset="utf-8" This is arbitrary, but used by the Huawei TF-A test code. Signed-off-by: Richard Henderson --- include/hw/arm/virt.h | 2 ++ hw/arm/virt.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index e1ddbea96b..5c0c8a67e4 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -86,6 +86,7 @@ enum { VIRT_ACPI_GED, VIRT_NVDIMM_ACPI, VIRT_PVTIME, + VIRT_RMM_MEM, VIRT_LOWMEMMAP_LAST, }; =20 @@ -159,6 +160,7 @@ struct VirtMachineState { bool virt; bool ras; bool mte; + bool rmm; bool dtb_randomness; OnOffAuto acpi; VirtGICType gic_version; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index ac626b3bef..067f16cd77 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -159,6 +159,7 @@ static const MemMapEntry base_memmap[] =3D { /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that siz= e */ [VIRT_PLATFORM_BUS] =3D { 0x0c000000, 0x02000000 }, [VIRT_SECURE_MEM] =3D { 0x0e000000, 0x01000000 }, + [VIRT_RMM_MEM] =3D { 0x0f000000, 0x00100000 }, [VIRT_PCIE_MMIO] =3D { 0x10000000, 0x2eff0000 }, [VIRT_PCIE_PIO] =3D { 0x3eff0000, 0x00010000 }, [VIRT_PCIE_ECAM] =3D { 0x3f000000, 0x01000000 }, @@ -1602,6 +1603,25 @@ static void create_secure_ram(VirtMachineState *vms, g_free(nodename); } =20 +static void create_rmm_ram(VirtMachineState *vms, + MemoryRegion *sysmem, + MemoryRegion *tag_sysmem) +{ + MemoryRegion *rmm_ram =3D g_new(MemoryRegion, 1); + hwaddr base =3D vms->memmap[VIRT_RMM_MEM].base; + hwaddr size =3D vms->memmap[VIRT_RMM_MEM].size; + + memory_region_init_ram(rmm_ram, NULL, "virt.rmm-ram", size, + &error_fatal); + memory_region_add_subregion(sysmem, base, rmm_ram); + + /* do not fill in fdt to hide rmm from normal world guest */ + + if (tag_sysmem) { + create_tag_ram(tag_sysmem, base, size, "mach-virt.rmm-tag"); + } +} + static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size) { const VirtMachineState *board =3D container_of(binfo, VirtMachineState, @@ -2283,6 +2303,10 @@ static void machvirt_init(MachineState *machine) machine->ram_size, "mach-virt.tag"); } =20 + if (vms->rmm) { + create_rmm_ram(vms, sysmem, tag_sysmem); + } + vms->highmem_ecam &=3D (!firmware_loaded || aarch64); =20 create_rtc(vms); @@ -2562,6 +2586,20 @@ static void virt_set_mte(Object *obj, bool value, Er= ror **errp) vms->mte =3D value; } =20 +static bool virt_get_rmm(Object *obj, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + return vms->rmm; +} + +static void virt_set_rmm(Object *obj, bool value, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + vms->rmm =3D value; +} + static char *virt_get_gic_version(Object *obj, Error **errp) { VirtMachineState *vms =3D VIRT_MACHINE(obj); @@ -3115,6 +3153,11 @@ static void virt_machine_class_init(ObjectClass *oc,= void *data) "guest CPU which implements the = ARM " "Memory Tagging Extension"); =20 + object_class_property_add_bool(oc, "rmm", virt_get_rmm, virt_set_rmm); + object_class_property_set_description(oc, "rmm", + "Set on/off to enable/disable ra= m " + "for the Realm Management Monito= r"); + object_class_property_add_bool(oc, "its", virt_get_its, virt_set_its); object_class_property_set_description(oc, "its", --=20 2.34.1