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

Fix missing overflow check when constructing suballocators #2322

Merged
merged 6 commits into from
Sep 14, 2023

Conversation

marc0246
Copy link
Contributor

@marc0246 marc0246 commented Sep 7, 2023

Fixes an oversight in #2316, where a safety precondition no longer holds. Previously all allocations were bounded by the root allocation which couldn't exceed DeviceLayout::MAX_SIZE, but now that regions are separate from allocations, it has to be checked separately somehow. I added a Region type solely for the sake of documentation, but I still don't know if it's best like this, where the suballocator would panic on construction (which results in a bit of duplication and could be more error-prone for an implementor of the trait) or whether Region should have private fields much like DeviceLayout and have both a safe and unsafe way to construct it. The thing is though that creating a suballocator isn't on the hot path unlike creating a DeviceLayout.

@marc0246 marc0246 marked this pull request as draft September 9, 2023 16:02
@marc0246
Copy link
Contributor Author

marc0246 commented Sep 9, 2023

I made the fields of Region private after all, not because the distinction between checked/unchecked construction of it is meaningful but rather because of the code duplication, both when checking the region and testing.

@marc0246 marc0246 marked this pull request as ready for review September 9, 2023 16:51
@Rua
Copy link
Contributor

Rua commented Sep 14, 2023

Is there a reason for not using Range<DeviceSize> to prevent overflow?

@marc0246
Copy link
Contributor Author

The bound is actually tighter than the bounds of the address space if you look. DeviceLayout::MAX_SIZE is i64::MAX.

@marc0246
Copy link
Contributor Author

But also, we use offset + size everywhere else like Vulkan. Though I did consider using ranges for private parts in the future to avoid some needless additions.

@Rua Rua merged commit 56e78d9 into vulkano-rs:master Sep 14, 2023
@marc0246 marc0246 deleted the suballocator-region branch September 14, 2023 10:02
hakolao pushed a commit to hakolao/vulkano that referenced this pull request Feb 20, 2024
…s#2322)

* Fix missing overflow check when constructing suballocators

* Add tests, fix borked code

* Make `Region`'s fields private

* Fix docs

* Borked the merge
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.

2 participants