Skip to content

[DeviceSanitizer] Check out-of-bounds on sycl::local_accessor #1532

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 6 commits into from
May 13, 2024

Conversation

AllanZyne
Copy link
Contributor

@AllanZyne AllanZyne commented Apr 22, 2024

@AllanZyne AllanZyne requested a review from a team as a code owner April 22, 2024 05:58
@github-actions github-actions bot added loader Loader related feature/bug sanitizer Sanitizer layer issues/changes/specification labels Apr 22, 2024
@AllanZyne
Copy link
Contributor Author

Hi @oneapi-src/unified-runtime-maintain, please review.
Thanks very much!

Comment on lines +82 to +101
struct KernelInfo {
ur_kernel_handle_t Handle;

ur_shared_mutex Mutex;
// Need preserve the order of local arguments
std::map<uint32_t, LocalArgsInfo> LocalArgs;

explicit KernelInfo(ur_kernel_handle_t Kernel) : Handle(Kernel) {
[[maybe_unused]] auto Result =
context.urDdiTable.Kernel.pfnRetain(Kernel);
assert(Result == UR_RESULT_SUCCESS);
}

~KernelInfo() {
[[maybe_unused]] auto Result =
context.urDdiTable.Kernel.pfnRelease(Handle);
assert(Result == UR_RESULT_SUCCESS);
}
};

Copy link
Contributor Author

@AllanZyne AllanZyne Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: KernelInfo related codes are duplicated with sycl::buffer PR #1533 (under review).

@AllanZyne
Copy link
Contributor Author

Kindly ping @oneapi-src/unified-runtime-maintain. Thanks very much!

Copy link
Contributor

@pbalcer pbalcer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks generally OK, but please have someone knowledgeable in the sanitizer review the PR.

Copy link
Contributor

@wenju-he wenju-he left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


struct LaunchInfo {
uintptr_t PrivateShadowOffset =
0; // don't move this field, we use it in AddressSanitizerPass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to help me better understand the above comment, can we move other fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can reorder other fields except PrivateShadowOffset, because we assume PrivateShadowOffset is the first field in ASanPass.

@pbalcer pbalcer added the ready to merge Added to PR's which are ready to merge label Apr 30, 2024
Copy link
Contributor

@yingcong-wu yingcong-wu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@kbenzie kbenzie merged commit 4c69624 into oneapi-src:main May 13, 2024
51 checks passed
steffenlarsen pushed a commit to intel/llvm that referenced this pull request May 16, 2024
…ccessor (#13503)

UR: oneapi-src/unified-runtime#1532

To check sycl::local_accessor(aka, dynamic local memory), we need to
extend a new argument in spir kernel, this is because:
- ASan needs to know some size information of local buffer, like its
size and size with redzone, so that it can poison its shadow memory
- By using this new argument, we can also pass some per-launch
information (that is, it is different in each launch of kernel). One
obvious example is SanitizerReport, which saves the error message, so
that we can store and print multiple error reports for one kernel with
different arguments. Another example is the shadow memory of local
memory, this should be different per-launch as well, since one kernel
can be launched multiple times and executed in parallel.

I named this argument as "__asan_launch", which is a pointer pointed to
"LaunchInfo" structure and allocated it in shared USM. To make this
pointer can be used in spir_func w/o extending their argument, I created
a global external local memory (external, so that it can be shared with
other translation units, and its instance is defined in libdevice), and
save the "__asan_launch" into this local memory immediately at the entry
of kernel.

UR can't check the name of kernel arguments, so it can't know if the
kernel has "__asan_launch". So I assume the "__asan_launch" is always
there, and added a check to prevent DAE pass from removing it.

---------

Co-authored-by: Maosu Zhao <maosu.zhao@intel.com>
Co-authored-by: Kenneth Benzie (Benie) <k.benzie@codeplay.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
loader Loader related feature/bug ready to merge Added to PR's which are ready to merge sanitizer Sanitizer layer issues/changes/specification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants