Skip to content

[DeviceSAN] Fix devicelib_exit hang and local memory issue #17923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions libdevice/sanitizer/asan_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,18 @@ bool MemIsZero(__SYCL_GLOBAL__ const char *beg, uptr size) {
static __SYCL_CONSTANT__ const char __mem_sanitizer_report[] =
"[kernel] SanitizerReport (ErrorType=%d, IsRecover=%d)\n";

void __asan_exit(ErrorType error_type) {
// Exit the kernel when we really need it
switch (error_type) {
case ErrorType::UNKNOWN:
case ErrorType::UNKNOWN_DEVICE:
case ErrorType::NULL_POINTER:
__devicelib_exit();
break;
default:
}
}

void __asan_internal_report_save(ErrorType error_type) {
const int Expected = ASAN_REPORT_NONE;
int Desired = ASAN_REPORT_START;
Expand Down Expand Up @@ -359,7 +371,7 @@ void __asan_internal_report_save(ErrorType error_type) {
SanitizerReport.ErrorTy,
SanitizerReport.IsRecover));
}
__devicelib_exit();
__asan_exit(error_type);
}

void __asan_internal_report_save(
Expand Down Expand Up @@ -435,7 +447,7 @@ void __asan_internal_report_save(
SanitizerReport.ErrorTy,
SanitizerReport.IsRecover));
}
__devicelib_exit();
__asan_exit(error_type);
}

///
Expand Down
5 changes: 0 additions & 5 deletions libdevice/sanitizer/msan_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ void __msan_report_error(const uint32_t size,
const uint32_t line,
const char __SYCL_CONSTANT__ *func, uptr origin = 0) {
__msan_internal_report_save(size, file, line, func, origin);

if (!GetMsanLaunchInfo->IsRecover) {
__devicelib_exit();
}
}

inline uptr __msan_get_shadow_cpu(uptr addr) {
Expand Down Expand Up @@ -250,7 +246,6 @@ DEVICE_EXTERN_C_NOINLINE void
__msan_warning_noreturn(const char __SYCL_CONSTANT__ *file, uint32_t line,
const char __SYCL_CONSTANT__ *func) {
__msan_internal_report_save(1, file, line, func, 0);
__devicelib_exit();
}

// For mapping detail, ref to
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ static bool isUnsupportedDeviceGlobal(GlobalVariable *G) {
return true;

if (G->getAddressSpace() == kSpirOffloadLocalAS)
return true;
return !ClSpirOffloadLocals;

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

// This case is handled by instrumentSyclStaticLocalMemory
if (G.getAddressSpace() == kSpirOffloadLocalAS)
continue;

Type *Ty = G.getValueType();
const uint64_t SizeInBytes = DL.getTypeAllocSize(Ty);
const uint64_t RightRedzoneSize = getRedzoneSizeForGlobal(SizeInBytes);
Expand Down