Skip to content

Commit 45e273c

Browse files
authored
[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 2eabf06 commit 45e273c

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) {
@@ -250,7 +246,6 @@ DEVICE_EXTERN_C_NOINLINE void
250246
__msan_warning_noreturn(const char __SYCL_CONSTANT__ *file, uint32_t line,
251247
const char __SYCL_CONSTANT__ *func) {
252248
__msan_internal_report_save(1, file, line, func, 0);
253-
__devicelib_exit();
254249
}
255250

256251
// 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
@@ -1708,7 +1708,7 @@ static bool isUnsupportedDeviceGlobal(GlobalVariable *G) {
17081708
return true;
17091709

17101710
if (G->getAddressSpace() == kSpirOffloadLocalAS)
1711-
return true;
1711+
return !ClSpirOffloadLocals;
17121712

17131713
Attribute Attr = G->getAttribute("sycl-device-image-scope");
17141714
return (!Attr.isStringAttribute() || Attr.getValueAsString() == "false");
@@ -2906,6 +2906,10 @@ void ModuleAddressSanitizer::instrumentDeviceGlobal(IRBuilder<> &IRB) {
29062906
if (isUnsupportedDeviceGlobal(&G))
29072907
continue;
29082908

2909+
// This case is handled by instrumentSyclStaticLocalMemory
2910+
if (G.getAddressSpace() == kSpirOffloadLocalAS)
2911+
continue;
2912+
29092913
Type *Ty = G.getValueType();
29102914
const uint64_t SizeInBytes = DL.getTypeAllocSize(Ty);
29112915
const uint64_t RightRedzoneSize = getRedzoneSizeForGlobal(SizeInBytes);

0 commit comments

Comments
 (0)