Skip to content
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

[UR] Add lifetime validation to validation layer #1121

Merged
merged 7 commits into from
Feb 9, 2024

Conversation

kswiecicki
Copy link
Contributor

@kswiecicki kswiecicki commented Nov 24, 2023

... and refactor the validation layer mako template.

Relies on: #1029.
Solves: #867.

scripts/core/common.yml Outdated Show resolved Hide resolved
@kswiecicki kswiecicki force-pushed the val-use-after-free branch 3 times, most recently from 43c1f19 to 93a709c Compare November 29, 2023 09:39
@codecov-commenter
Copy link

codecov-commenter commented Nov 29, 2023

Codecov Report

Attention: 623 lines in your changes are missing coverage. Please review.

Comparison is base (32e2533) 15.36% compared to head (c0f0a70) 15.33%.

Files Patch % Lines
source/loader/layers/validation/ur_valddi.cpp 2.68% 617 Missing ⚠️
test/layers/validation/fixtures.hpp 75.00% 4 Missing ⚠️
source/loader/layers/validation/ur_leak_check.hpp 93.10% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1121      +/-   ##
==========================================
- Coverage   15.36%   15.33%   -0.04%     
==========================================
  Files         240      241       +1     
  Lines       34182    34820     +638     
  Branches     3788     3989     +201     
==========================================
+ Hits         5252     5339      +87     
- Misses      28879    29430     +551     
  Partials       51       51              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kswiecicki kswiecicki force-pushed the val-use-after-free branch 2 times, most recently from 65d5318 to 07e1009 Compare November 29, 2023 13:33
@kswiecicki kswiecicki changed the title [UR] Add support for handle tracking [UR] Add lifetime validation to validation layer Nov 29, 2023
@kswiecicki kswiecicki marked this pull request as ready for review November 29, 2023 13:41
@kswiecicki kswiecicki force-pushed the val-use-after-free branch 2 times, most recently from 6f797f1 to 4487664 Compare December 4, 2023 09:49
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.

right now this checks whether the provided ptr is a valid ptr to something, not necessarily an object of the expected type. Shouldn't be too hard to add?

scripts/core/INTRO.rst Outdated Show resolved Hide resolved
scripts/templates/valddi.cpp.mako Outdated Show resolved Hide resolved
scripts/templates/valddi.cpp.mako Outdated Show resolved Hide resolved
@@ -256,6 +256,8 @@ Layers currently included with the runtime are as follows:
- Enables non-adapter-specific parameter validation (e.g. checking for null values).
* - UR_LAYER_LEAK_CHECKING
- Performs some leak checking for API calls involving object creation/destruction.
* - UR_LAYER_LIFETIME_VALIDATION
- Performs lifetime validation on objects used in API calls. Requires UR_LAYER_LEAK_CHECKING.
Copy link
Contributor

Choose a reason for hiding this comment

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

please explain what "lifetime validation" is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added an explanation, take a look.

@kswiecicki
Copy link
Contributor Author

right now this checks whether the provided ptr is a valid ptr to something, not necessarily an object of the expected type. Shouldn't be too hard to add?

I've added std::type_index info to the RefRuntimeInfo and check for the index equality when checking a reference validity.
I was trying to also print handle type names but they were mangled and showed internal type names like ur_adapter_handle_t_ * instead of ur_adapter_handle_t.

@kswiecicki kswiecicki force-pushed the val-use-after-free branch 2 times, most recently from e72dc55 to 510bd27 Compare December 8, 2023 15:12

void SetUp() {
valAdaptersTest::SetUp();
adapter = adapters[0]; // TODO - which to choose?
Copy link
Contributor

Choose a reason for hiding this comment

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

the way the tests are run there will only ever be one adapter. so [0] is fine.

@pbalcer
Copy link
Contributor

pbalcer commented Dec 11, 2023

I was trying to also print handle type names but they were mangled and showed internal type names like ur_adapter_handle_t_ * instead of ur_adapter_handle_t.

I think that's fine. If you want to do this, one approach might be to pass the type name as a string from the generated layer to the class with runtime info. Would allow you to do away with typeindex and get correct type names. Not sure if it's worth it.

@kswiecicki kswiecicki force-pushed the val-use-after-free branch 4 times, most recently from b79dbdd to 8b686dc Compare December 20, 2023 09:43
@kswiecicki kswiecicki force-pushed the val-use-after-free branch 3 times, most recently from 952ba35 to 57d0a47 Compare December 27, 2023 14:09
@kswiecicki kswiecicki force-pushed the val-use-after-free branch 6 times, most recently from 7eac656 to b160633 Compare January 23, 2024 12:48
@@ -102,7 +102,7 @@ name: "$x_kernel_handle_t"
--- #--------------------------------------------------------------------------
type: handle
desc: "Handle of a queue object"
class: $xPlatform
class: $xQueue
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be moved into another PR. Otherwise this one lgtm and we can merge it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. The queue fix is here #1285.

@kswiecicki kswiecicki force-pushed the val-use-after-free branch 2 times, most recently from fd803c8 to a08fc85 Compare January 26, 2024 09:04
@kswiecicki kswiecicki force-pushed the val-use-after-free branch 8 times, most recently from 925c5e8 to 51be719 Compare February 5, 2024 15:19
@kswiecicki kswiecicki force-pushed the val-use-after-free branch 3 times, most recently from e8dd668 to 1ba7c7b Compare February 8, 2024 15:51
The leak checking feature has been expanded to include handles
obtained via the ...Get() functions.
Match files in leak checking tests also account for the
..Create(), ..Get() and ..Release() functions used in test
setups.
... handle type checks.
@pbalcer pbalcer merged commit 186bfb9 into oneapi-src:main Feb 9, 2024
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants