[compiler-rt] 30532c1 - [scudo] Fix secondary caching for mte (#150156)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 28 12:56:19 PDT 2025
Author: Christopher Ferris
Date: 2025-07-28T12:56:16-07:00
New Revision: 30532c13d2fb592af9cb651f6571beca4b48b705
URL: https://github.com/llvm/llvm-project/commit/30532c13d2fb592af9cb651f6571beca4b48b705
DIFF: https://github.com/llvm/llvm-project/commit/30532c13d2fb592af9cb651f6571beca4b48b705.diff
LOG: [scudo] Fix secondary caching for mte (#150156)
The current code always unmaps a secondary allocation when MTE is
enabled. Fix this to match the comment, namely only unmap if MTE was
enabled and is no longer enabled after acquiring the lock.
In addition, allow quaratine to work in the secondary even if MTE is not
enabled.
Added:
Modified:
compiler-rt/lib/scudo/standalone/secondary.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index 286e5d332f57c..f04c5b7cfc2ea 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -269,7 +269,8 @@ class MapAllocatorCache {
Entry.MemMap = MemMap;
Entry.Time = UINT64_MAX;
- if (useMemoryTagging<Config>(Options)) {
+ bool MemoryTaggingEnabled = useMemoryTagging<Config>(Options);
+ if (MemoryTaggingEnabled) {
if (Interval == 0 && !SCUDO_FUCHSIA) {
// Release the memory and make it inaccessible at the same time by
// creating a new MAP_NOACCESS mapping on top of the existing mapping.
@@ -302,7 +303,7 @@ class MapAllocatorCache {
if (Entry.Time != 0)
Entry.Time = Time;
- if (useMemoryTagging<Config>(Options) && QuarantinePos == -1U) {
+ if (MemoryTaggingEnabled && !useMemoryTagging<Config>(Options)) {
// If we get here then memory tagging was disabled in between when we
// read Options and when we locked Mutex. We can't insert our entry into
// the quarantine or the cache because the permissions would be wrong so
@@ -310,7 +311,8 @@ class MapAllocatorCache {
unmapCallBack(Entry.MemMap);
break;
}
- if (Config::getQuarantineSize() && useMemoryTagging<Config>(Options)) {
+
+ if (Config::getQuarantineSize()) {
QuarantinePos =
(QuarantinePos + 1) % Max(Config::getQuarantineSize(), 1u);
if (!Quarantine[QuarantinePos].isValid()) {
@@ -513,9 +515,10 @@ class MapAllocatorCache {
Quarantine[I].invalidate();
}
}
+ QuarantinePos = -1U;
+
for (CachedBlock &Entry : LRUEntries)
Entry.MemMap.setMemoryPermission(Entry.CommitBase, Entry.CommitSize, 0);
- QuarantinePos = -1U;
}
void disable() NO_THREAD_SAFETY_ANALYSIS { Mutex.lock(); }
More information about the llvm-commits
mailing list