Skip to content

Commit 2d99519

Browse files
authored
[DeviceMSAN] Fix MemToShadow algorithm and VA reservation (#16475)
UR: oneapi-src/unified-runtime#2507
1 parent 68840f1 commit 2d99519

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,14 +671,12 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
671671
};
672672

673673
std::string SanitizeVal;
674-
std::string SanitizeArg;
675674
size_t sanitizer_lib_idx = getSingleBuildTarget();
676675
if (Arg *A = Args.getLastArg(options::OPT_fsanitize_EQ,
677676
options::OPT_fno_sanitize_EQ)) {
678677
if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
679678
A->getValues().size() == 1) {
680679
SanitizeVal = A->getValue();
681-
SanitizeArg = A->getAsString(Args);
682680
}
683681
} else {
684682
// User can pass -fsanitize=address to device compiler via
@@ -703,12 +701,10 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
703701
for (const std::string &Arg : ArgVals) {
704702
if (Arg.find("-fsanitize=address") != std::string::npos) {
705703
SanitizeVal = "address";
706-
SanitizeArg = Arg;
707704
break;
708705
}
709706
if (Arg.find("-fsanitize=memory") != std::string::npos) {
710707
SanitizeVal = "memory";
711-
SanitizeArg = Arg;
712708
break;
713709
}
714710
}

libdevice/cmake/modules/SYCLLibdevice.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ if (NOT MSVC AND UR_SANITIZER_INCLUDE_DIR)
239239
device.h atomic.hpp spirv_vars.h
240240
${UR_SANITIZER_INCLUDE_DIR}/asan/asan_libdevice.hpp
241241
include/asan_rtl.hpp
242+
include/sanitizer_defs.hpp
242243
include/spir_global_var.hpp
243244
${sycl-compiler_deps})
244245

@@ -296,6 +297,7 @@ if (NOT MSVC AND UR_SANITIZER_INCLUDE_DIR)
296297
device.h atomic.hpp spirv_vars.h
297298
${UR_SANITIZER_INCLUDE_DIR}/msan/msan_libdevice.hpp
298299
include/msan_rtl.hpp
300+
include/sanitizer_defs.hpp
299301
include/spir_global_var.hpp
300302
sycl-compiler)
301303
endif()

libdevice/sanitizer/msan_rtl.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,15 @@ inline uptr __msan_get_shadow_cpu(uptr addr) {
132132

133133
inline uptr __msan_get_shadow_pvc(uptr addr, uint32_t as) {
134134
// Device USM only
135-
uptr shadow_ptr = ((__SYCL_GLOBAL__ MsanLaunchInfo *)__MsanLaunchInfo.get())
136-
->GlobalShadowOffset +
137-
(addr & 0x3FFF'FFFF'FFFFULL);
138-
return shadow_ptr;
135+
auto shadow_begin = ((__SYCL_GLOBAL__ MsanLaunchInfo *)__MsanLaunchInfo.get())
136+
->GlobalShadowOffset;
137+
auto shadow_end = ((__SYCL_GLOBAL__ MsanLaunchInfo *)__MsanLaunchInfo.get())
138+
->GlobalShadowOffsetEnd;
139+
if (addr < shadow_begin) {
140+
return addr + (shadow_begin - 0xff00'0000'0000'0000ULL);
141+
} else {
142+
return addr - (0xff00'ffff'ffff'ffffULL - shadow_end);
143+
}
139144
}
140145

141146
} // namespace
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# commit 93fc1331edfd5519ea1fab42a8b96abe9e53672f
2-
# Merge: 259b67db d2c04518
1+
# commit fe6c83a3a40e69eaa0c4829c8ba99b03e05bb4e2
2+
# Merge: 93fc1331 cf0c9482
33
# Author: aarongreig <aaron.greig@codeplay.com>
4-
# Date: Thu Dec 26 16:52:33 2024 +0000
5-
# Merge pull request #2402 from yingcong-wu/yc/1202-mmap-failure
6-
# [DevASAN][CPU] bugfix for mmap return value check.
7-
set(UNIFIED_RUNTIME_TAG 93fc1331edfd5519ea1fab42a8b96abe9e53672f)
4+
# Date: Fri Dec 27 17:39:52 2024 +0000
5+
# Merge pull request #2507 from AllanZyne/review/yang/fix_msan_shadow
6+
# [DeviceMSAN] Fix MemToShadow algorithm and VA reservation
7+
set(UNIFIED_RUNTIME_TAG fe6c83a3a40e69eaa0c4829c8ba99b03e05bb4e2)

0 commit comments

Comments
 (0)