From nobody Wed Feb 11 08:38:20 2026 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=1681488327; cv=none; d=zohomail.com; s=zohoarc; b=hjl+noymgnC5Yl0dyaNGq9fKUQLZd3ekaWyUJBXxVsutFN5eE5YEWidNfec8GfLQqe8YS8luDTKR+3JkeFf+aEE/r6zhzaPdPT/gBIKiII7fZdXbp5bY85eBIJuL5ZmOLVt2UBw9K+YqZFFLujnrKnHvzkL2wBe3ouPsfHHfRcU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681488327; 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=jUHq0yTT6mZpyW8ymPG55BvWQqRfjylp1jFh1uUnshs=; b=Lj6zeqmyRfXHj+POetlpDDf+TGkSqxuaGbmjk6mY4szubTy9/ks4c4vsXbuTzw2m/tq6/mfq211PO+l6Bq+ySSDi649lsNIRzpeE5cafBSJ9cyGkd0cjbeJ/q5Sp4uX1dxQNK81HYVlXZjSyce+CYILddfcb9r2ziS6Qg28zY7A= 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 1681488327674594.0925394366545; Fri, 14 Apr 2023 09:05:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pnLuX-0006IZ-3E; Fri, 14 Apr 2023 12:04:29 -0400 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 1pnLuU-0006Gn-5V for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:26 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pnLuN-0007uA-Fr for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:25 -0400 Received: by mail-wm1-x333.google.com with SMTP id l10-20020a05600c1d0a00b003f04bd3691eso21024842wms.5 for ; Fri, 14 Apr 2023 09:04:16 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c22c800b003ef71d541cbsm4673752wmg.1.2023.04.14.09.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 09:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681488255; x=1684080255; 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=jUHq0yTT6mZpyW8ymPG55BvWQqRfjylp1jFh1uUnshs=; b=Z86cmet/oFJLig9vLG0ILm1/FNhYYRfu7A35GrX/shAqhvqcdzEqz52CrVEekTAwIL S7vqSxDS293h99upQmb/0f0z6oJfVc/L2jmw7XvlnkJnVpL9w2xY5SdzsJU7oHtBbQ/f 0ZmHvFaV/D3jn0wRqc1KzHMbywPywnVPFpPM2PauCtRe2tO/TfLoMMEGI8jsOVfXGw16 lFkYf6rCmx2ERV9/xNB33KmSoSoxio1GY1SD+s0S6ceGCEVAcrKdgq0WyRW0+DMWUu6l bkYVsLJrMyVNAJDomEXoHZ0z4matpM6MIIVth4qaVD8kCwVQDDdJGgPIXmYG9QknG3fs ABKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681488255; x=1684080255; 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=jUHq0yTT6mZpyW8ymPG55BvWQqRfjylp1jFh1uUnshs=; b=LENF2SLkge35pyvyn27lxBrxHk4GXvQc2vKzqVnKsC7YeDhVAE4v1InXPI1FFK/HgY DbPYcu8sGLufLH8UyDFy2zz74FwQnIAaTjdIdJ3pV3kJdX0O1OU9WzuS6XU1hkdywyfV QuYWowjZlFO00DXun6Ts8EVKpXUUTeKxLTLykIy8wzyjv3KKGyNjA3V1iIdEN2wy5Z5A fZSZwYok6fqduEuu4a2kW6d1dsd1/2VIsNILHP+xcn33q6tljYVb7WOdki3Qfq7CeXry 90rSX4wnlJO1EBzw8iManQRUZOkPs3MBobUJdPjB/UItlILzBZ0jhYeDwp9rYETwE6XE lGBA== X-Gm-Message-State: AAQBX9d2fsueOUoWN9iPyl/JvZxxvFcOj0QWAR0kGQf203n8bO7cA5De aYWHaeSeTrf9sHrOgfCJAKPB2w== X-Google-Smtp-Source: AKy350YETcn+yNaYy3urhJGZcD9eUjvqxBohnD8pITojghUBs73GleaAY5brqOTF4d5ub0v7kHbWQA== X-Received: by 2002:a05:600c:2289:b0:3ee:6161:7d98 with SMTP id 9-20020a05600c228900b003ee61617d98mr4732437wmf.16.1681488255598; Fri, 14 Apr 2023 09:04:15 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 1/3] target/arm: Don't allow stage 2 page table walks to downgrade to NS Date: Fri, 14 Apr 2023 17:04:11 +0100 Message-Id: <20230414160413.549801-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414160413.549801-1-peter.maydell@linaro.org> References: <20230414160413.549801-1-peter.maydell@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=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1681488329056100001 Content-Type: text/plain; charset="utf-8" Bit 63 in a Table descriptor is only the NSTable bit for stage 1 translations; in stage 2 it is RES0. We were incorrectly looking at it all the time. This causes problems if: * the stage 2 table descriptor was incorrectly setting the RES0 bit * we are doing a stage 2 translation in Secure address space for a NonSecure stage 1 regime -- in this case we would incorrectly do an immediate downgrade to NonSecure A bug elsewhere in the code currently prevents us from getting to the second situation, but when we fix that it will be possible. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/arm/ptw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 6d72950a795..06865227642 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1403,17 +1403,18 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1= Translate *ptw, descaddrmask &=3D ~indexmask_grainsize; =20 /* - * Secure accesses start with the page table in secure memory and + * Secure stage 1 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. + * Stage 2 never gets this kind of downgrade. */ tableattrs =3D is_secure ? 0 : (1 << 4); =20 next_level: descaddr |=3D (address >> (stride * (4 - level))) & indexmask; descaddr &=3D ~7ULL; - nstable =3D extract32(tableattrs, 4, 1); + nstable =3D !regime_is_stage2(mmu_idx) && extract32(tableattrs, 4, 1); if (nstable) { /* * Stage2_S -> Stage2 or Phys_S -> Phys_NS --=20 2.34.1 From nobody Wed Feb 11 08:38:20 2026 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=1681488303; cv=none; d=zohomail.com; s=zohoarc; b=l6qweXvuZYy9phBPozc/VwNFE9UpL+zSE0DyGsb5CjXl1XxTbNJVcf6E3yArFDOe9kTNKUt0hkpn9MGg2jg+6AnyTNraB3f8WnMfxcei/NYBt2PHC/3hZHWy3QwOrAuhJnFIoWa09XwCSgNT9eua41TY2fKgVDRV2c4XAdbAHdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681488303; 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=JuAuDSPuE/JnH8NiYlJET7XN0aNFOky+lUCpFOTs4Zw=; b=eE3NFRJeud/U/qlFdCMpz05QTSKe87kF8g3Zuz37DDucVSpm08pVB/7ZLrEcQrV2oMKLSq2DxvmFhD1NPTVZOmicTDzn2SVYREQe7/X8CkZmxS1tGf2vgYnghfYPc2P+Y8yXGwDlS/Od61YHs08eY2RCHa3NBOn9dN74JyCifiI= 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 1681488302493700.2702273439764; Fri, 14 Apr 2023 09:05:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pnLuW-0006HX-MO; Fri, 14 Apr 2023 12:04:28 -0400 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 1pnLuT-0006Bp-2E for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:25 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pnLuN-0007uI-Fy for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:24 -0400 Received: by mail-wr1-x42f.google.com with SMTP id i3so8715562wrc.4 for ; Fri, 14 Apr 2023 09:04:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c22c800b003ef71d541cbsm4673752wmg.1.2023.04.14.09.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 09:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681488256; x=1684080256; 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=JuAuDSPuE/JnH8NiYlJET7XN0aNFOky+lUCpFOTs4Zw=; b=kLOeWaX547vj2pq9D70zKNPaDV2RtAzetYWxUr128oko7f8OrZUSj9uAqtoiaAWBVU cHfQRrK7bV3ZVJZdEpxlpu7QspX39juGTt7RLh2SyLNAqa+c694OuaatZAMD6hjt5tSY pQZahx95+Uf//b2mZ3ibI/6BIgIS6z0f7Yt0H/SrrSam19xTEMRKmivV7Qhx5t10/BBI 00AvFpo2IcjAQ3UUhrRmvo43KEav6MaWX+T3mXDQckHy9OXIqg4hpNuBWh/7RI5IBknv BElLWPMhfn5zfootKIq6Yz9hQhyQKJQx81jlu0+Q2iD652GdrwWAJaJhtxgO0xTQna1M 8FFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681488256; x=1684080256; 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=JuAuDSPuE/JnH8NiYlJET7XN0aNFOky+lUCpFOTs4Zw=; b=c/2GxQokhjvhIouT79vjCZtfEbJXo+uW82wy1Z1WrG0gpLmBwvC5BhFasz5YAlZ5xc N2n2pJvvfObFMNqA3GmcQiF6qsxA7ommlUXAOfyPxrZ6p5dOCag+wMG3K98k0VWp9o8m Tu6Hg289/uao8PFcuOK74KGqaF/STLbhSDswIkbfa6aY5zXSdbBQqVBl1bPw8rYqTNnk t9u1KSqgdZUIFTmFV0nA7CANtTufbbHbvfRh6rzbRRMXGxEhfDkXExHfq8+wjDfUOSi3 DiB5jGkYDr9Fuw7CA+/JgoL+DYullkOQgX0fhvPHUa4zpZ9AfKRHpHJUMqPO8zX9dxUS iR1g== X-Gm-Message-State: AAQBX9dKjPobiV/SU24Kk0LbueFHNf5S66gZLwpkrc75ldlOyIbt//gd TxSl6deXxe7Vi9My/DCaHrlWFw== X-Google-Smtp-Source: AKy350aoELpSJpUWuWwrCAEY8h2icAWq0MZvVLjaT17n75UpYyAEAILD9dI7QgW5GrnUUCTBDOdqLA== X-Received: by 2002:a5d:4fc1:0:b0:2f5:9b1f:da81 with SMTP id h1-20020a5d4fc1000000b002f59b1fda81mr4293233wrw.54.1681488256115; Fri, 14 Apr 2023 09:04:16 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 2/3] target/arm: Set ptw->out_secure correctly for stage 2 translations Date: Fri, 14 Apr 2023 17:04:12 +0100 Message-Id: <20230414160413.549801-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414160413.549801-1-peter.maydell@linaro.org> References: <20230414160413.549801-1-peter.maydell@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=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1681488305088100003 Content-Type: text/plain; charset="utf-8" In S1_ptw_translate(), we are in one of two situations: (1) translating an S1 page table walk through S2 (2) translating an S2 page table walk through a physical regime In case (1), ptw->in_secure indicates whether S1 is a Secure or NonSecure translation regime. In case (2), ptw->in_secure indicates whether this stage 2 translation is for a Secure IPA or a NonSecure IPA. In particular, because of the VTCR_EL2.NSW and VSTCR_EL2.SW bits, we can be doing a translation of a NonSecure IPA where the page tables are in the Secure space. Correct the setting of the ptw->out_secure value for the regime-is-physical case: * it depends on whether s2_mmu_idx is Phys_S or Phys, not on the value of is_secure * we don't need to look at the VTCR_EL2.NSW and VSTCR.SW bits again here, as we already did that in get_phys_addr_twostage() to set the correct in_ptw_idx This error doesn't currently cause a problem in itself because we are incorrectly setting ptw->in_secure to s2walk_secure in get_phys_addr_twostage(), but we need to fix this before we can correct that problem. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/ptw.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 06865227642..c1e124df495 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -249,7 +249,7 @@ static bool S1_ptw_translate(CPUARMState *env, S1Transl= ate *ptw, /* Regime is physical. */ ptw->out_phys =3D addr; pte_attrs =3D 0; - pte_secure =3D is_secure; + pte_secure =3D s2_mmu_idx =3D=3D ARMMMUIdx_Phys_S; } ptw->out_host =3D NULL; ptw->out_rw =3D false; @@ -291,13 +291,15 @@ static bool S1_ptw_translate(CPUARMState *env, S1Tran= slate *ptw, fi->s1ns =3D !is_secure; return false; } + /* Check if page table walk is to secure or non-secure PA space. */ + ptw->out_secure =3D (is_secure + && !(pte_secure + ? env->cp15.vstcr_el2 & VSTCR_SW + : env->cp15.vtcr_el2 & VTCR_NSW)); + } else { + /* Regime is physical */ + ptw->out_secure =3D pte_secure; } - - /* Check if page table walk is to secure or non-secure PA space. */ - ptw->out_secure =3D (is_secure - && !(pte_secure - ? env->cp15.vstcr_el2 & VSTCR_SW - : env->cp15.vtcr_el2 & VTCR_NSW)); ptw->out_be =3D regime_translation_big_endian(env, mmu_idx); return true; =20 --=20 2.34.1 From nobody Wed Feb 11 08:38:20 2026 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=1681488318; cv=none; d=zohomail.com; s=zohoarc; b=I1LjIYPomqrEM9skW7JdOx94Onfc+YBQC6/QeCjH/tp1d9DUeOLqnJZQHvnw5N/qsb30lMCVCVkbGiFI6k79WUQ7nSjpIBY2XDz0R/x7k9HSIuFoLHBjQEURCSUdlTVYD6wamjlQZmltMO+OyCuwue46hVUGBZvRLaGjF2NXImA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681488318; 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=YMa/jjOI3MD8EqV7FtoT5tBQ7kPLlHERL0vXAgxCR5Y=; b=K1eZp0RgLkJ1LpEPZpGGQ2VwyglYbOKIPGOAP+tdZYnVT4upSO7asCfKDL3dFoHsuIZ6DblA1SeTC91ShC9Y1y7R2qVT/ginwBnRU72t2Xs13qMNCweKAhWI4u79EFMgZMcIAwxAeeDxpdiNVNBbAngqqlViGyK7IFO2X9RFzZM= 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 1681488318295779.7986556257814; Fri, 14 Apr 2023 09:05:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pnLux-0006b7-F1; Fri, 14 Apr 2023 12:04:55 -0400 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 1pnLuT-0006Dg-6E for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:25 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pnLuN-0007ue-GU for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:24 -0400 Received: by mail-wm1-x330.google.com with SMTP id k36-20020a05600c1ca400b003f0a7c483feso3112669wms.4 for ; Fri, 14 Apr 2023 09:04:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c22c800b003ef71d541cbsm4673752wmg.1.2023.04.14.09.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 09:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681488257; x=1684080257; 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=YMa/jjOI3MD8EqV7FtoT5tBQ7kPLlHERL0vXAgxCR5Y=; b=RrqyY3tLwUYPzR1bC3UHzCc/SLAMfeEomSCZrPQWrF8sZzq/33u1xwNjteMq/p46ZF S0LnjNBVUDf+x0TPgjS+2YeRPFC/KgYdeHreKpYSS0M4ZjxNdaMQLc5E6mfEWjGdsnpr I9wCu1+H0fH8lBLYsVnCmMERFn7hGD4kFVWoWRtxiwkMKp59h41MoA3NO7TAfkUvhMNZ QrpOyd8iBxnYZTg34rX4CFxobc2ym5kP6SudUE2pZXmDhVNtn/qG5Feq1+fcVs3oKx4b xyAAwl2tTmj5WRyFu8dk+1WRXS/+nB94YttBCwidaw6SSlI36qYeCz2QZGyyQxXAHsyI On9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681488257; x=1684080257; 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=YMa/jjOI3MD8EqV7FtoT5tBQ7kPLlHERL0vXAgxCR5Y=; b=Y7QNli9d9CzZfoKgVs6JiW/Qjx94xwj5sGTTcdHZwQQPTnNv4Gy4qd2yXujeMZRcIP Uz7V2wS3lrkKEbdy7DNbudjJxLGDjIs3MHAQRvf/AiaBdriRAndPFw3pRow0hOmhQc1I 6/z5gyluf4eAeGT/IdEyn5cpNGyB9eJ2ug8GsdjMTmdJRDj6PCK7wc4Wep7FygrpjByP ppSDXbgevKW5q2vcsPblFgLr5wzxadrWdlF9liJfMxxj+d/JvXNHOr3HVnFq34K76gUw N/jRFvkUgHMvz2MH4iHUWOPfVKOkB4QT3RAi3RhbyhbsL+nLX4S+U5bKdZ/go+JTHveD siqg== X-Gm-Message-State: AAQBX9e0Z4wWVbfITQ2cDw9qnkHywkROhr3O3UJ+gnaI0MzDqf2vuSEn VmMTE6DVDnGEOPsn09keL7neig== X-Google-Smtp-Source: AKy350ay4iPAg5bbSmh1LgUiLSeXEpH2u0jZzTqu0CQ7Fz9Iy8H6Jorw7PLMnNjFRK3NRIeGGmlKZA== X-Received: by 2002:a05:600c:ad6:b0:3f0:bf4d:8c64 with SMTP id c22-20020a05600c0ad600b003f0bf4d8c64mr1709819wmr.22.1681488257013; Fri, 14 Apr 2023 09:04:17 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 3/3] target/arm: handle ipa_secure vs s2walk_secure correctly Date: Fri, 14 Apr 2023 17:04:13 +0100 Message-Id: <20230414160413.549801-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414160413.549801-1-peter.maydell@linaro.org> References: <20230414160413.549801-1-peter.maydell@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=2a00:1450:4864:20::330; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1681488318959100002 Content-Type: text/plain; charset="utf-8" In get_phys_addr_twostage() when we set up the stage 2 translation, we currently incorrectly set all of in_mmu_idx, in_ptw_idx and in_secure based on s2walk_secure. Here s2walk_secure is true if we should be doing this stage 2 walk to physical memory. ipa_secure is true if the intermediate physical address we got from stage 1 is secure. The VSTCR_EL2.SW and VTCR_EL2.NSW bits allow the guest to configure secure EL2 so that these two things are different, eg: * a stage 2 walk for an NS IPA done to secure physical memory (where the translation table base address and other parameters for the walk come from the NS control registers VTTBR_EL2 and VTCR_EL2) * a stage 2 walk for an S IPA done to non-secure physical memory (where the parameters from the walk come from the S control registers VSTTBR_EL2 and VSTCR_EL2) To tell get_phys_addr_lpae() to do this, we need to pass in an in_mmu_idx based on ipa_secure, and an in_ptw_idx based on s2walk_secure. The in_secure parameter follows in_mmu_idx, as usual. Note that this change relies on fixes in the previous two commits ("Don't allow stage 2 page table walks to downgrade to NS" and "Set ptw->out_secure correctly for stage 2 translations"). Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1600 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- This change also means that v8M, which also uses get_phys_addr_twostage(), is no longer using a ptw->in_mmu_idx calculated based on s2walk_secure, which was always a little strange given that v8M doesn't do any kind of s2 walk, even though it didn't produce incorrect behaviour. --- target/arm/ptw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index c1e124df495..2ee2b0b9241 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -2741,9 +2741,9 @@ static bool get_phys_addr_twostage(CPUARMState *env, = S1Translate *ptw, } =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_mmu_idx =3D ipa_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; ptw->in_ptw_idx =3D s2walk_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_= NS; - ptw->in_secure =3D s2walk_secure; + ptw->in_secure =3D ipa_secure; =20 /* * S1 is done, now do S2 translation. --=20 2.34.1