Skip to content

Commit fc335af

Browse files
AllanZyneKornevNikita
authored andcommitted
[DeviceMSAN] Fix e2e tests crashed on OpenCL CPU (#18150)
Unlike ASAN, MSAN needs "__devicelib_exit()" because if "j" is an uninitialized value in "data[j]", this will cause memory crash on CPU. But sometimes "__devicelib_exit()" will hang on OpenMP (GPU), so I added a new option "recover" to control it.
1 parent b84fb78 commit fc335af

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

libdevice/sanitizer/msan_rtl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ inline uptr __msan_get_shadow_pvc(uptr addr, uint32_t as) {
215215
return GetMsanLaunchInfo->CleanShadow;
216216
}
217217

218+
inline void __msan_exit() {
219+
if (!GetMsanLaunchInfo->IsRecover)
220+
__devicelib_exit();
221+
}
222+
218223
} // namespace
219224

220225
#define MSAN_MAYBE_WARNING(type, size) \
@@ -225,6 +230,7 @@ inline uptr __msan_get_shadow_pvc(uptr addr, uint32_t as) {
225230
return; \
226231
if (UNLIKELY(s)) { \
227232
__msan_report_error(size, file, line, func, o); \
233+
__msan_exit(); \
228234
} \
229235
}
230236

@@ -236,13 +242,19 @@ MSAN_MAYBE_WARNING(u64, 8)
236242
DEVICE_EXTERN_C_NOINLINE void
237243
__msan_warning(const char __SYCL_CONSTANT__ *file, uint32_t line,
238244
const char __SYCL_CONSTANT__ *func) {
245+
if (!GetMsanLaunchInfo)
246+
return;
239247
__msan_report_error(1, file, line, func);
248+
__msan_exit();
240249
}
241250

242251
DEVICE_EXTERN_C_NOINLINE void
243252
__msan_warning_noreturn(const char __SYCL_CONSTANT__ *file, uint32_t line,
244253
const char __SYCL_CONSTANT__ *func) {
254+
if (!GetMsanLaunchInfo)
255+
return;
245256
__msan_internal_report_save(1, file, line, func, 0);
257+
__msan_exit();
246258
}
247259

248260
// For mapping detail, ref to

unified-runtime/source/loader/layers/sanitizer/msan/msan_interceptor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ ur_result_t MsanInterceptor::prepareLaunch(
479479

480480
LaunchInfo.Data.Host.DeviceTy = DeviceInfo->Type;
481481
LaunchInfo.Data.Host.Debug = getContext()->Options.Debug ? 1 : 0;
482+
LaunchInfo.Data.Host.IsRecover = getContext()->Options.Recover ? 1 : 0;
482483

483484
// Clean shadow
484485
// Its content is always zero, and is used for unsupport memory types

unified-runtime/source/loader/layers/sanitizer/sanitizer_common/sanitizer_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void SanitizerOptions::Init(const std::string &EnvName,
4646
Parser.ParseBool("print_stats", PrintStats);
4747
Parser.ParseBool("detect_leaks", DetectLeaks);
4848
Parser.ParseBool("halt_on_error", HaltOnError);
49+
Parser.ParseBool("recover", Recover);
4950

5051
Parser.ParseUint64("quarantine_size_mb", MaxQuarantineSizeMB, 0, UINT32_MAX);
5152
Parser.ParseUint64("redzone", MinRZSize, 16);

unified-runtime/source/loader/layers/sanitizer/sanitizer_common/sanitizer_options.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct SanitizerOptions {
3131
bool DetectKernelArguments = true;
3232
bool DetectLeaks = true;
3333
bool HaltOnError = true;
34+
bool Recover = false;
3435

3536
void Init(const std::string &EnvName, logger::Logger &Logger);
3637
};

0 commit comments

Comments
 (0)