From: "Ard Biesheuvel" <ard.biesheuvel@linaro.org>
To: devel@edk2.groups.io
Cc: leif@nuviainc.com, Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH v2 1/9] ArmPlatformPkg/PrePi: replace set/way cache ops with by-VA ones
Date: Wed, 4 Mar 2020 19:12:38 +0100 [thread overview]
Message-ID: <20200304181246.23513-2-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20200304181246.23513-1-ard.biesheuvel@linaro.org>
Cache maintenance operations by set/way are only intended to be used
in the context of on/offlining a core, while it has been taken out of
the coherency domain. Any use intended to ensure that the contents of
the cache have made it to main memory is unreliable, since cacheline
migration and non-architected system caches may cause these contents
to linger elsewhere, without being visible in main memory once the
MMU and caches are disabled.
In KVM on Linux, there are horrid hacks in place to ensure that such
set/way operations are trapped, and replaced with a single by-VA
clean/invalidate of the entire guest VA space once the MMU state
changes, which can be costly, and is unnecessary if we manage the
caches a bit more carefully, and perform maintenance by virtual
address only.
So let's get rid of the call to ArmInvalidateDataCache () in the
PrePeiCore startup code, and instead, invalidate the UEFI memory
region by virtual address, which is the only memory region we will
be touching with the caches and MMU both disabled and enabled.
(This will lead to data corruption if data written with the MMU off
is shadowed by clean, stale cachelines that stick around when the
MMU is enabled again.)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Tested-By: Pete Batard <pete@akeo.ie>
---
ArmPlatformPkg/PrePi/PeiMPCore.inf | 1 +
ArmPlatformPkg/PrePi/PeiUniCore.inf | 1 +
ArmPlatformPkg/PrePi/PrePi.c | 8 +++++---
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/ArmPlatformPkg/PrePi/PeiMPCore.inf b/ArmPlatformPkg/PrePi/PeiMPCore.inf
index 9c5da0d42a7b..053f9fd9e616 100644
--- a/ArmPlatformPkg/PrePi/PeiMPCore.inf
+++ b/ArmPlatformPkg/PrePi/PeiMPCore.inf
@@ -37,6 +37,7 @@ [Packages]
[LibraryClasses]
BaseLib
+ CacheMaintenanceLib
DebugLib
DebugAgentLib
ArmLib
diff --git a/ArmPlatformPkg/PrePi/PeiUniCore.inf b/ArmPlatformPkg/PrePi/PeiUniCore.inf
index ee9b05b25337..78d218ae09ca 100644
--- a/ArmPlatformPkg/PrePi/PeiUniCore.inf
+++ b/ArmPlatformPkg/PrePi/PeiUniCore.inf
@@ -37,6 +37,7 @@ [Packages]
[LibraryClasses]
BaseLib
+ CacheMaintenanceLib
DebugLib
DebugAgentLib
ArmLib
diff --git a/ArmPlatformPkg/PrePi/PrePi.c b/ArmPlatformPkg/PrePi/PrePi.c
index 2bb144958139..254fb331733e 100644
--- a/ArmPlatformPkg/PrePi/PrePi.c
+++ b/ArmPlatformPkg/PrePi/PrePi.c
@@ -8,6 +8,7 @@
#include <PiPei.h>
+#include <Library/CacheMaintenanceLib.h>
#include <Library/DebugAgentLib.h>
#include <Library/PrePiLib.h>
#include <Library/PrintLib.h>
@@ -178,8 +179,6 @@ CEntryPoint (
// Data Cache enabled on Primary core when MMU is enabled.
ArmDisableDataCache ();
- // Invalidate Data cache
- ArmInvalidateDataCache ();
// Invalidate instruction cache
ArmInvalidateInstructionCache ();
// Enable Instruction Caches on all cores.
@@ -200,6 +199,10 @@ CEntryPoint (
// If not primary Jump to Secondary Main
if (ArmPlatformIsPrimaryCore (MpId)) {
+
+ InvalidateDataCacheRange ((VOID *)UefiMemoryBase,
+ FixedPcdGet32(PcdSystemMemoryUefiRegionSize));
+
// Goto primary Main.
PrimaryMain (UefiMemoryBase, StacksBase, StartTimeStamp);
} else {
@@ -209,4 +212,3 @@ CEntryPoint (
// DXE Core should always load and never return
ASSERT (FALSE);
}
-
--
2.17.1
next prev parent reply other threads:[~2020-03-04 18:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-04 18:12 [PATCH v2 0/9] ArmPkg: eradicate and deprecate by set/way cache ops Ard Biesheuvel
2020-03-04 18:12 ` Ard Biesheuvel [this message]
2020-03-05 16:23 ` [PATCH v2 1/9] ArmPlatformPkg/PrePi: replace set/way cache ops with by-VA ones Leif Lindholm
2020-03-04 18:12 ` [PATCH v2 2/9] ArmPkg/ArmMmuLib ARM: remove dummy constructor Ard Biesheuvel
2020-03-04 18:12 ` [PATCH v2 3/9] ArmPkg/ArmMmuLib ARM: split ArmMmuLibCore.c into core and update code Ard Biesheuvel
2020-03-04 18:12 ` [PATCH v2 4/9] ArmPkg/ArmMmuLib ARM: cache-invalidate initial page table entries Ard Biesheuvel
2020-03-04 18:12 ` [PATCH v2 5/9] ArmPkg/ArmMmuLib AARCH64: " Ard Biesheuvel
2020-03-04 18:12 ` [PATCH v2 6/9] ArmPkg/ArmLib: move set/way helper functions into private header Ard Biesheuvel
2020-03-04 18:12 ` [PATCH v2 7/9] ArmPkg/ArmLib: clean up library includes Ard Biesheuvel
2020-03-04 18:12 ` [PATCH v2 8/9] ArmPkg/ArmLib: remove bogus protocol declaration Ard Biesheuvel
2020-03-04 18:12 ` [PATCH v2 9/9] ArmPkg/ArmLib: ASSERT on set/way cache ops being used with MMU on Ard Biesheuvel
2020-03-05 16:29 ` [PATCH v2 0/9] ArmPkg: eradicate and deprecate by set/way cache ops Leif Lindholm
2020-03-05 21:40 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200304181246.23513-2-ard.biesheuvel@linaro.org \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox