[compiler-rt] [scudo] Avoid splitting aligned allocations on Trusty (PR #69281)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 13:50:52 PST 2024
================
@@ -122,7 +122,28 @@ bool mapSecondary(const Options &Options, uptr CommitBase, uptr CommitSize,
Flags |= MAP_RESIZABLE;
Flags |= MAP_ALLOWNOMEM;
- const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * getPageSizeCached();
+ const uptr PageSize = getPageSizeCached();
+ if (SCUDO_TRUSTY) {
+ /*
+ * On Trusty we need AllocPos to be usable for shared memory, which cannot
+ * cross multiple mappings. This means we need to split around AllocPos
+ * and not over it. We can only do this if the address is page-aligned.
+ */
+ const uptr TaggedSize = AllocPos - CommitBase;
+ if (useMemoryTagging<Config>(Options) && isAligned(TaggedSize, PageSize)) {
+ return MemMap.remap(CommitBase, TaggedSize, "scudo:secondary",
+ MAP_MEMTAG | Flags) &&
+ MemMap.remap(AllocPos, CommitSize - TaggedSize, "scudo:secondary",
+ Flags);
+ } else {
+ const uptr RemapFlags =
+ (useMemoryTagging<Config>(Options) ? MAP_MEMTAG : 0) | Flags;
+ return MemMap.remap(CommitBase, CommitSize, "scudo:secondary",
+ RemapFlags);
+ }
+ }
----------------
ChiaHungDuan wrote:
Just FYI, the reason we have the `MaxUnusedCacheBytes` is,
```
ommit 3f71ce85897cc92190af6a66c5b2dcffc85212e2
Author: Peter Collingbourne <peter at pcc.me.uk>
Date: Mon Dec 21 18:39:03 2020 -0800
...
Buffer underflow detection has been implemented on hardware supporting
memory tagging by tagging the memory region between the start of the
mapping and the start of the allocation with a non-zero tag. Due to
the cost of pre-tagging secondary allocations and the memory bandwidth
cost of tagged accesses, the allocation itself uses a tag of 0 and
only the first four pages have memory tagging enabled.
...
In your case, when there's a huge mapping and the `AllocPos` is not aligned to the page boundary, you may bump into some tagging overhead. The huge allocation is not usual on Trusty so I think it should be fine.
https://github.com/llvm/llvm-project/pull/69281
More information about the llvm-commits
mailing list