Skip to content

Commit b84fb78

Browse files
AllanZyneKornevNikita
authored andcommitted
[DeviceSAN] Fix devicelib_exit hang and local memory issue (#17923)
- devicelib_exit: use it when we really need it, such as detecting nullpointer access, to prevent from openmp hang - fix local memory load/store isn't instrumented
1 parent 2523098 commit b84fb78

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

libdevice/sanitizer/asan_rtl.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,18 @@ bool MemIsZero(__SYCL_GLOBAL__ const char *beg, uptr size) {
330330
static __SYCL_CONSTANT__ const char __mem_sanitizer_report[] =
331331
"[kernel] SanitizerReport (ErrorType=%d, IsRecover=%d)\n";
332332

333+
void __asan_exit(ErrorType error_type) {
334+
// Exit the kernel when we really need it
335+
switch (error_type) {
336+
case ErrorType::UNKNOWN:
337+
case ErrorType::UNKNOWN_DEVICE:
338+
case ErrorType::NULL_POINTER:
339+
__devicelib_exit();
340+
break;
341+
default:
342+
}
343+
}
344+
333345
void __asan_internal_report_save(ErrorType error_type) {
334346
const int Expected = ASAN_REPORT_NONE;
335347
int Desired = ASAN_REPORT_START;
@@ -359,7 +371,7 @@ void __asan_internal_report_save(ErrorType error_type) {
359371
SanitizerReport.ErrorTy,
360372
SanitizerReport.IsRecover));
361373
}
362-
__devicelib_exit();
374+
__asan_exit(error_type);
363375
}
364376

365377
void __asan_internal_report_save(
@@ -435,7 +447,7 @@ void __asan_internal_report_save(
435447
SanitizerReport.ErrorTy,
436448
SanitizerReport.IsRecover));
437449
}
438-
__devicelib_exit();
450+
__asan_exit(error_type);
439451
}
440452

441453
///

libdevice/sanitizer/msan_rtl.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ void __msan_report_error(const uint32_t size,
148148
const uint32_t line,
149149
const char __SYCL_CONSTANT__ *func, uptr origin = 0) {
150150
__msan_internal_report_save(size, file, line, func, origin);
151-
152-
if (!GetMsanLaunchInfo->IsRecover) {
153-
__devicelib_exit();
154-
}
155151
}
156152

157153
inline uptr __msan_get_shadow_cpu(uptr addr) {
@@ -247,7 +243,6 @@ DEVICE_EXTERN_C_NOINLINE void
247243
__msan_warning_noreturn(const char __SYCL_CONSTANT__ *file, uint32_t line,
248244
const char __SYCL_CONSTANT__ *func) {
249245
__msan_internal_report_save(1, file, line, func, 0);
250-
__devicelib_exit();
251246
}
252247

253248
// For mapping detail, ref to

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ static bool isUnsupportedDeviceGlobal(GlobalVariable *G) {
16671667
return true;
16681668

16691669
if (G->getAddressSpace() == kSpirOffloadLocalAS)
1670-
return true;
1670+
return !ClSpirOffloadLocals;
16711671

16721672
Attribute Attr = G->getAttribute("sycl-device-image-scope");
16731673
return (!Attr.isStringAttribute() || Attr.getValueAsString() == "false");
@@ -2858,6 +2858,10 @@ void ModuleAddressSanitizer::instrumentDeviceGlobal(IRBuilder<> &IRB) {
28582858
if (isUnsupportedDeviceGlobal(&G))
28592859
continue;
28602860

2861+
// This case is handled by instrumentSyclStaticLocalMemory
2862+
if (G.getAddressSpace() == kSpirOffloadLocalAS)
2863+
continue;
2864+
28612865
Type *Ty = G.getValueType();
28622866
const uint64_t SizeInBytes = DL.getTypeAllocSize(Ty);
28632867
const uint64_t RightRedzoneSize = getRedzoneSizeForGlobal(SizeInBytes);

0 commit comments

Comments
 (0)