oneapi-src / unified-memory-framework

A library for constructing allocators and memory pools. It also contains broadly useful abstractions and utilities for memory management. UMF allows users to manage multiple memory pools characterized by different attributes, allowing certain allocation types to be isolated from others and allocated using different hardware resources as required.
https://oneapi-src.github.io/unified-memory-framework/
Other
30 stars 22 forks source link

Memory poisoning failure for allocations on a device #634

Open PatKamin opened 1 month ago

PatKamin commented 1 month ago

Environment Information

Please provide a reproduction of the bug:

How often bug is revealed:

always (always, often, rare)

Actual behavior:

AddressSanitizer: CHECK failed: asan_mapping.h:359 "((AddrIsInMem(p))) != (0)" (0x0, 0x0)
#0 0x55c51330ce81 in __asan::CheckUnwind() asan_rtl.cpp.o
#1 0x55c513325814 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (unified-runtime/build/bin/fuzztest-base+0x165814) (BuildId: b0932a052df3ffbe6c2d5a2e30dfccfbe77ef111)
#2 0x55c51330590c in __asan::ShadowSegmentEndpoint::ShadowSegmentEndpoint(unsigned long) (unified-runtime/build/bin/fuzztest-base+0x14590c) (BuildId: b0932a052df3ffbe6c2d5a2e30dfccfbe77ef111)
#3 0x55c5133056d8 in __asan_poison_memory_region (unified-runtime/build/bin/fuzztest-base+0x1456d8) (BuildId: b0932a052df3ffbe6c2d5a2e30dfccfbe77ef111)
#4 0x7fa8fa7928b4 in utils_annotate_memory_inaccessible(void*, unsigned long) unified-runtime/build/_deps/unified-memory-framework-src/src/utils/utils_sanitizers.h:162:5
#5 0x7fa8fa78495a in memoryProviderAlloc(umf_memory_provider_t*, unsigned long, unsigned long) unified-runtime/build/_deps/unified-memory-framework-src/src/pool/pool_disjoint.cpp:403:5
#6 0x7fa8fa784228 in Slab::Slab(Bucket&) unified-runtime/build/_deps/unified-memory-framework-src/src/pool/pool_disjoint.cpp:441:14
#7 0x7fa8fa79bb40 in std::__detail::_MakeUniq<Slab>::__single_object std::make_unique<Slab, Bucket&>(Bucket&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unique_ptr.h:1065:34
#8 0x7fa8fa78c5a0 in Bucket::getAvailSlab(bool&) unified-runtime/build/_deps/unified-memory-framework-src/src/pool/pool_disjoint.cpp:637:41
#9 0x7fa8fa78ce16 in Bucket::getChunk(bool&) unified-runtime/build/_deps/unified-memory-framework-src/src/pool/pool_disjoint.cpp:660:19
#10 0x7fa8fa7911f9 in DisjointPool::AllocImpl::allocate(unsigned long, unsigned long, bool&) unified-runtime/build/_deps/unified-memory-framework-src/src/pool/pool_disjoint.cpp:889:22
#11 0x7fa8fa79450d in DisjointPool::aligned_malloc(unsigned long, unsigned long) unified-runtime/build/_deps/unified-memory-framework-src/src/pool/pool_disjoint.cpp:1043:22
#12 0x7fa8fa7b9b5c in auto umf_memory_pool_ops_t umf::detail::poolOpsBase<DisjointPool>()::'lambda1'(void*, auto...)::operator()<unsigned long, unsigned long>(void*, auto...) const unified-runtime/build/_deps/unified-memory-framework-src/src/pool/../cpp_helpers.hpp:74:5
#13 0x7fa8fa7b9aec in auto umf_memory_pool_ops_t umf::detail::poolOpsBase<DisjointPool>()::'lambda1'(void*, auto...)::__invoke<unsigned long, unsigned long>(void*, auto...) unified-runtime/build/_deps/unified-memory-framework-src/src/pool/../cpp_helpers.hpp:74:5
#14 0x7fa8fd093921 in umfPoolAlignedMalloc unified-runtime/build/_deps/unified-memory-framework-src/src/memory_pool.c:12
#15 0x7fa8fa44f6b3 in urUSMDeviceAlloc unified-runtime/source/adapters/level_zero/usm.cpp:426:13

Expected behavior:

CHECK passes.

Details

We need a way to determine in Disjoint Pool whether the allocation is made on a host memory or a device memory. In cases of allocations made on a host memory, we can enable memory poison/unpoison.

Additional information about Priority and Help Requested:

Are you willing to submit a pull request with a proposed change? Yes (Yes, No)

Requested priority: High (Showstopper, High, Medium, Low)

PatKamin commented 1 month ago

One way to enable memory poisoning for host allocations is to introduce a new parameter in DisjointPool params struct: image Then set it when creating a Disjoint Pool that will allocate only host memory.