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

MmapRegion: relax mmap size constraints #178

Merged
merged 1 commit into from
Oct 18, 2021

Conversation

alindima
Copy link
Contributor

For the build_raw() alternative of the MmapRegion,
the implementation was validating that the length of
the mapping was a multiple of the page size.

This generally makes sense, since the OS will round up
to the nearest multiple anyway and only allocate full
pages.
There is one corner case though where this needs to be
relaxed: when mapping a file with a length not divisible
by the pagesize.

According to the POSIX reference, the length will be rounded
up and the extra memory zero-ed. Memory accesses will work
as expected, even beyond the actual file length (but within the
allocated memory), but any writes will not be persisted to the
filesystem and the backing device.

This is a use case where mapping an "uneven" length makes sense,
so that such "out-of-bounds" checks can be caught by accesses
via vm-memory primitives.

This commit removes this constraint.

Signed-off-by: alindima [email protected]

For the build_raw() alternative of the MmapRegion,
the implementation was validating that the length of
the mapping was a multiple of the page size.

This generally makes sense, since the OS will round up
to the nearest multiple anyway and only allocate full
pages.
There is one corner case though where this needs to be
relaxed: when mapping a file with a length not divisible
by the pagesize.

According to the POSIX reference, the length will be rounded
up and the extra memory zero-ed. Memory accesses will work
as expected, even beyond the actual file length (but within the
allocated memory), but any writes will not be persisted to the
filesystem and the backing device.

This is a use case where mapping an "uneven" length makes sense,
so that such "out-of-bounds" checks can be caught by accesses
via vm-memory primitives.

This commit removes this constraint.

Signed-off-by: alindima <[email protected]>
Copy link
Member

@bonzini bonzini left a comment

Choose a reason for hiding this comment

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

Removing InvalidSize is technically an API change, since it can break match statements. Assuming no one cares, the patch is okay.

@lauralt
Copy link
Contributor

lauralt commented Oct 18, 2021

@alindima can you add an entry for this in the changelog?

@jiangliu jiangliu merged commit a49a173 into rust-vmm:main Oct 18, 2021
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.

4 participants