[PATCH] D85227: [Draft][MSAN] Cache stack traces and chained origins

Gui Andrade via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 10:35:31 PDT 2020


guiand created this revision.
guiand added reviewers: eugenis, vitalybuka.
Herald added subscribers: llvm-commits, Sanitizers, jfb, hiraditya.
Herald added projects: Sanitizers, LLVM.
guiand requested review of this revision.

Prevent (excessive) expensive stack unwinding and depot lookups by introducing smaller caches external to the depots.

The stack trace depot is cached by "stack trace hash" -- a TLS value constantly updated by instrumentation in the MSAN LLVM pass. The origin depot is cached by a cheap 32-bit hash over the two IDs comprising the edge in the graph.

Each depot is accessed only after missing in a L1 <https://reviews.llvm.org/L1> and L2 cache. The L1 <https://reviews.llvm.org/L1> is small and per-thread, and the L2 is a few times larger and is global to all threads. Both are direct-mapped using the hash. On collision, the old entry is evicted.

In order to prevent stack unwinding in the case of a cache hit, MSan no longer passes `StackTrace` objects among its internal functions. Instead, I use a new `StackUnwindCtx` object which stores the parameters we need for unwinding on demand.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85227

Files:
  compiler-rt/lib/msan/msan.cpp
  compiler-rt/lib/msan/msan.h
  compiler-rt/lib/msan/msan_allocator.cpp
  compiler-rt/lib/msan/msan_interceptors.cpp
  compiler-rt/lib/msan/msan_new_delete.cpp
  compiler-rt/lib/msan/msan_origin.h
  compiler-rt/lib/msan/msan_poisoning.cpp
  compiler-rt/lib/msan/msan_poisoning.h
  compiler-rt/lib/sanitizer_common/sanitizer_hashcache.h
  compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.h
  compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85227.282959.patch
Type: text/x-patch
Size: 31660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200804/2237fac5/attachment.bin>


More information about the llvm-commits mailing list