[UR][L0] Diagnose errors in host memory registration API#22370
Open
againull wants to merge 1 commit into
Open
Conversation
- The Level Zero driver does not reliably diagnose alignment errors for the external system memory mapping path: an unaligned pointer is reported as ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY and an unaligned size is silently accepted. Validate host-page alignment of the pointer and size directly in the Level Zero adapter. - Validate null pointer and zero size, returning UR_RESULT_ERROR_INVALID_VALUE. - Reject a registration whose range [pHostMem, pHostMem + size) would overflow the host address space, returning UR_RESULT_ERROR_INVALID_VALUE. - Replace the bare assert that the mapped device VA equals the host pointer with a real runtime check: on mismatch, undo the mapping and return an error instead of silently handing back an unusable registration. - Handle UR_DEVICE_INFO_USM_HOST_ALLOC_REGISTER_SUPPORT_EXP in the L0 device info query, returning whether the external system memory mapping extension is supported. The enum existed but was previously unhandled. Assisted-by: Claude
pbalcer
approved these changes
Jun 19, 2026
Comment on lines
+938
to
948
|
|
||
| // This extension maps the existing host memory in place, so the mapped | ||
| // device virtual address must match the host pointer that was registered. | ||
| // If the driver ever returns a different address we cannot honor the | ||
| // contract, so undo the mapping and report a failure rather than silently | ||
| // handing back an unusable registration. | ||
| if (mappedMem != pHostMem) { | ||
| ZE_CALL_NOCHECK(zeMemFree, (hContext->getZeHandle(), mappedMem)); | ||
| return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
I think this is a bit overzealous and too defensive. It would be a severe driver bug for this to happen. It's not an error the application can reasonably handle. I think the assert is the correct thing to do here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Assisted-by: Claude