[llvm-dev] RFC: Generalize means the sanitizers work with memory
Sean Silva via llvm-dev
llvm-dev at lists.llvm.org
Mon Feb 27 18:59:27 PST 2017
IIRC, Hal mentioned that he did something like this for a no-MMU HPC
environment he was working in.
-- Sean Silva
On Thu, Feb 23, 2017 at 10:16 AM, Ivan A. Kosarev via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> RFC: Generalize means the sanitizers work with memory
> Currently, LLVM sanitizers, such as Asan and Tsan, are tied to a specific
> memory model that relies on presence of hardware support for virtual
> This prevents sanitizers from being used on platforms that lack such
> but otherwise are capable of running sanitized programs. Our research
> indicates that adding support for such platforms is possible with a
> small amount of changes to the sanitizers source code and zero performance
> size penalty on currently supported systems. We also found that these
> clarify and formalize the functional and performance dependencies between
> sanitizers and system memory so they can be considered an improvement in
> terms of design and readability regardless of the added capabilities. One
> think of it as a zero-cost abstraction layer.
> The Approach
> To support platforms that do not have hardware virtual memory managers,
> we need to introduce the concept of physical memory pages that work as the
> storage for data that sanitizers currently read and write by virtual
> addresses. In presence of the concept of physical memory, every time we
> virtual memory we have to translate the given virtual address to a physical
> one. For example, this check:
> *(u8 *)MEM_TO_SHADOW(allocated) == 0
> *MEM_TO_PSHADOW(allocated) == 0
> where the MEM_TO_PSHADOW(mem) macro is defined as:
> #define MEM_TO_PSHADOW(mem) VSHADOW_TO_PSHADOW(MEM_TO_VSHADOW(mem))
> #define MEM_TO_VSHADOW(mem) /* Whatever currently MEM_TO_SHADOW() is. */
> The VSHADOW_TO_PSHADOW(vs) macro returns a pointer to a byte within a
> physical page that corresponds to the given virtual address and allocates
> page if it has not been allocated before. On platforms that leverage
> virtual memory managers this macro returns the virtual address as a
> #define VSHADOW_TO_PSHADOW(vs) (reinterpret_cast<u8*>((vs)))
> Physical pages are required to be aligned by their size. The size of
> pages is a multiple of the shadow memory granularity (8 bytes for Asan) and
> not less than the size of the widest scalar access we have to support (16
> bytes). This makes trivial finding page offsets, which we need to implement
> RTL functions efficiently. This also simplifies handling of aligned
> to physical memory as they are known to not cross bounds of physical pages.
> Note that RTL functions have to be fixed to not rely on specific size,
> location or order of physical pages.
> In addition to the facilities that allow handling of individual accesses to
> the virtual memory we also need a set of functions that efficiently perform
> operations on specified ranges of virtual addresses:
> // Fills a virtual memory with a given value. May release zeroed pages. For
> // DFsan we may need a version of this function that takes 16-bit values to
> // fill with.
> void vshadow_memset(uptr vs, u8 value, uptr size);
> // Similarly to vshadow_memset(), this function fills a range of virtual
> // memory with a given value and additionally claims that range as
> // so the memory manager is not required to support modifying accesses for
> // these addresses.
> void fill_rodata_vshadow(uptr vs, u8 value, uptr size);
> // Copies potentially overlapping memory regions.
> void vshadow_memmove(uptr dest, uptr src, uptr size);
> // Returns the virtual address of the first non-zero byte in a given
> // address range. Can also be used to test for zeroed regions.
> uptr find_non_zero_vshadow_byte(uptr vs, uptr size);
> // Explicitly releases pages that fit the specified range.
> void release_vshadow(uptr vs, uptr size);
> The Proof-of-Concept Patch
> To make sure the approach is feasible we have prepared a patch that
> fixes the Asan and Tsan RTL and instrumentation parts to translate virtual
> shadow memory addresses to physical ones and mmap() shadow memory as we
> it. This way we simulate a software virtual memory manager that allocates
> physical storage for shadow memory on-demand.
> We used that to mock RTL for the sanitizers tests. With this mock in place
> pass all Tsan tests and fail on 3 of 610 Asan tests:
> The first two tests rely on specific memory map after initializtion of the
> shadow memory and the latter takes too long to complete. It would probably
> acceptable to XFAIL them when run with a software memory manager enabled
> then consider ways to adopt them as necessary on a per-test basis.
> * * *
> With this paper we propose the changes that make it possible to use
> on plaforms that have no MMUs to be part of the mainline. However, before
> moving further we would like some feedback from the community so comments
> very appreciated.
> If the approach is fine, we will prepare a set of patches shortly.
> Thank you,
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev