-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Update pin_user_pages() calls for Direct I/O #17006
Merged
Merged
Conversation
This file contains 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
amotin
reviewed
Jan 29, 2025
bwatkinson
force-pushed
the
user_backed_iov_iter
branch
from
January 29, 2025 20:26
3d49053
to
d593704
Compare
amotin
approved these changes
Jan 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As much as I understand that code I have no objections, just few cosmetic comments.
Originally openzfs#16856 updated Linux Direct I/O requests to use the new pin_user_pages API. However, it was an oversight that this PR only handled iov_iter's of type ITER_IOVEC and ITER_UBUF. Other iov_iter types may try and use the pin_user_pages API if it is available. This can lead to panics as the iov_iter is not being iterated over correctly in zfs_uio_pin_user_pages(). Unfortunately, generic iov_iter API's that call pin_user_page_fast() are protected as GPL only. Rather than update zfs_uio_pin_user_pages() to account for all iov_iter types, we can simply just call zfs_uio_get_dio_page_iov_iter() if the iov_iter type is not ITER_IOVEC or ITER_UBUF. zfs_uio_get_dio_page_iov_iter() calls the iov_iter_get_pages() calls that can handle any iov_iter type. In the future it might be worth using the exposed iov_iter iterator functions that are included in the header iov_iter.h since v6.7. These functions allow for any iov_iter type to be iterated over and advanced while applying a step function during iteration. This could possibly be leveraged in zfs_uio_pin_user_pages(). A new ZFS test case was added to test that a ITER_BVEC is handled correctly using this new code path. This test case was provided though issue openzfs#16956. Signed-off-by: Brian Atkinson <batkinson@lanl.gov> Closes openzfs#16956
bwatkinson
force-pushed
the
user_backed_iov_iter
branch
from
January 30, 2025 00:06
d593704
to
e46af9b
Compare
ixhamza
approved these changes
Jan 30, 2025
behlendorf
approved these changes
Jan 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks for running this down!
behlendorf
added
Status: Accepted
Ready to integrate (reviewed, tested)
and removed
Status: Code Review Needed
Ready for review and testing
labels
Jan 30, 2025
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.
Originally #16856 updated Linux Direct I/O requests to use the new pin_user_pages API. However, it was an oversight that this PR only handled iov_iter's of type ITER_IOVEC and ITER_UBUF. Other iov_iter types may try and use the pin_user_pages API if it is available. This can lead to panics as the iov_iter is not being iterated over correctly in zfs_uio_pin_user_pages().
Unfortunately, generic iov_iter API's that call pin_user_page_fast() are protected as GPL only. Rather than update zfs_uio_pin_user_pages() to account for all iov_iter types, we can simply just call zfs_uio_get_dio_page_iov_iter() if the iov_iter type is not ITER_IOVEC or ITER_UBUF. zfs_uio_get_dio_page_iov_iter() calls the iov_iter_get_pages() calls that can handle any iov_iter type.
In the future it might be worth using the exposed iov_iter iterator functions that are included in the header iov_iter.h since v6.7. These functions allow for any iov_iter type to be iterated over and advanced while applying a step function during iteration. This could possibly be leveraged in zfs_uio_pin_user_pages().
A new ZFS test case was added to test that a ITER_BVEC is handled correctly using this new code path. This test case was provided though issue #16956.
Signed-off-by: Brian Atkinson batkinson@lanl.gov
Closes #16956
Updated when to use
pin_user_pages_unlocked()
based on theiov_iter
type.Motivation and Context
00It resolves a kernel panic that can occur in
zfs_uio_pin_user_pages()
when trying to iterate over astruct iov_iter
t hat is not aITER_IOVEC
orITER_UBUF
.Fixes issue #16956.
Description
Updated the check in
zfs_uio_get_dio_pages_alloc()
to only callzfs_uio_pin_user_pages()
if theiov_iter
type isITER_IOVEC
orITER_UBUF
. These two types are the onlyiov_iter
types taken into account for iterating inzfs_uio_pin_user_pages()
. While we could manually code in otheriov_iter
types to iterate over them, that seems ripe for error in the future if the kernel introduces anotherstruct iov_iter
type in the future. Addedboolean_t
variable calledpinned
tozfs_uio_dio_t
to signal whetherpin_user_pages_unlocked()
was used for pages for Direct I/O.Due to this update, I did have to add back the check for
iov_iter_get_pages2()
in the config checks. This will still need to used in kernels >= v6.0 if we need to callzfs_uio_get_dio_pages_iov_iter()
.A ZTS test case
dio_loopback_dev
was added that uses the test that caused a kernel panic in #16956.How Has This Been Tested?
Tested by running the direct ZTS tests on:
Types of changes
Checklist:
Signed-off-by
.