From nobody Thu May 2 21:46:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55555+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55555+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583445019; cv=none; d=zohomail.com; s=zohoarc; b=jAXOH50i/ZJS4FKGH//DG2AQLdMAuglVn+DTN0Vc7Z1P/p04FQkrz4LS7ocP6p717/xkTTklF9H2DarZ9RHBzlhmFuKcbyudccuBK8YzQmuF6SXUCMEIC1hrZ61ZRIRzkG6kMAXzIPeIWzUKrTfDIHB5scVYhMcb6g/gXhzdNFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583445019; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=iOcfxVNkTE7yT0d8uw6EZrbu7hKCAAqtRaPQ9u7FbxM=; b=jXyAvfr7S5/NDTSS1hkrlWEJ8QRkYn9seHYxu2/J5rgWSXFzvCujMe/1WmvD9nRH33tF1foerScVKe18dYUqSagS6/99bbiWbyjfiA0+Jab9X0fnRIsZ9aD5hV/okhowJXX9W65A9U4vhaH1JUibob4+tWHZ6kvUHuptE8v5v4k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55555+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583445019945717.3616598109505; Thu, 5 Mar 2020 13:50:19 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id hdZyYY1788612xuUGFpzYqGV; Thu, 05 Mar 2020 13:50:19 -0800 X-Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by mx.groups.io with SMTP id smtpd.web11.2706.1583445018593351813 for ; Thu, 05 Mar 2020 13:50:19 -0800 X-Received: by mail-wm1-f66.google.com with SMTP id i9so196994wml.4 for ; Thu, 05 Mar 2020 13:50:18 -0800 (PST) X-Gm-Message-State: aXnr9JohGdLSWgC6LVwUFVzYx1787277AA= X-Google-Smtp-Source: ADFU+vsqC67KlhqZxfi5GmEtVoOEw95X5LOD7xrzwLfgtqVtD7VSR8/oNSFwUFQPsg7lS6cEV/zj1w== X-Received: by 2002:a7b:c05a:: with SMTP id u26mr807663wmc.74.1583445016941; Thu, 05 Mar 2020 13:50:16 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id c8sm36901619wru.7.2020.03.05.13.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 13:50:15 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH] ArmPkg/ArmMmuLib AARCH64: invalidate page tables before populating them Date: Thu, 5 Mar 2020 22:50:10 +0100 Message-Id: <20200305215010.29436-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583445019; bh=8Iw27j4BLv6bmhcDoWtcoADz3TM6qTtXCSJHQE19R6Q=; h=Cc:Date:From:Reply-To:Subject:To; b=Qk/7nX7ZLT1ISqqMv8OlpIs2XhwSZarxaQpPo1NO2Zszs0ltztjA5IrggOQGBqRuHks FiHTjtFnAbiYh165QDnchH5WNixPDO5DlgdZcyJlfN5I5c111pWO6xS/V2iI4BPAf/woV myICkkKTWhz4wuZQGgYAypklfjYYCYaE9ig= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As it turns out, ARMv8 (DDI 0487E.a D4.4.5) also permits accesses made with the MMU and caches off to hit in the caches, so to ensure that any modifications we make before enabling the MMU are visible afterwards as well, we should invalidate page tables right after allocation like we do now on ARM, if the MMU is still disabled at that point. Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Libr= ary/ArmMmuLib/AArch64/ArmMmuLibCore.c index 204e33c75f95..b5d6b66806f8 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -282,6 +282,15 @@ GetBlockEntryListFromAddress ( return NULL; } =20 + if (!ArmMmuEnabled ()) { + // + // Make sure we are not inadvertently hitting in the caches + // when populating the page tables. + // + InvalidateDataCacheRange (TranslationTable, + TT_ENTRY_COUNT * sizeof(UINT64)); + } + // Populate the newly created lower level table SubTableBlockEntry =3D TranslationTable; for (Index =3D 0; Index < TT_ENTRY_COUNT; Index++) { @@ -306,6 +315,14 @@ GetBlockEntryListFromAddress ( return NULL; } =20 + if (!ArmMmuEnabled ()) { + // + // Make sure we are not inadvertently hitting in the caches + // when populating the page tables. + // + InvalidateDataCacheRange (TranslationTable, + TT_ENTRY_COUNT * sizeof(UINT64)); + } ZeroMem (TranslationTable, TT_ENTRY_COUNT * sizeof(UINT64)); =20 // Fill the new BlockEntry with the TranslationTable @@ -697,6 +714,14 @@ ArmConfigureMmu ( *TranslationTableSize =3D RootTableEntryCount * sizeof(UINT64); } =20 + if (!ArmMmuEnabled ()) { + // + // Make sure we are not inadvertently hitting in the caches + // when populating the page tables. + // + InvalidateDataCacheRange (TranslationTable, + RootTableEntryCount * sizeof(UINT64)); + } ZeroMem (TranslationTable, RootTableEntryCount * sizeof(UINT64)); =20 TranslationTableAttribute =3D TT_ATTR_INDX_INVALID; --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55555): https://edk2.groups.io/g/devel/message/55555 Mute This Topic: https://groups.io/mt/71759645/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-