block: Fix dio_bio_alloc() to set BIO_PAGE_PINNED
Subsystems (3)
PATCH 1/1 block: Fix dio_bio_alloc() to set BIO_PAGE_PINNED
Fix dio_bio_alloc() to set BIO_PAGE_PINNED, not BIO_PAGE_REFFED, so that the bio code unpins the pinned pages rather than putting a ref on them.
The issue was causing:
WARNING: CPU: 6 PID: 2220 at mm/gup.c:76 try_get_folio
This can be caused by creating a file on a loopback UDF filesystem, opening it O_DIRECT and making two writes to it from the same source buffer.
--- fs/direct-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/direct-io.c +2 -1
@@ -415,7 +415,8 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio,else bio->bi_end_io = dio_bio_end_io;/* for now require references for all pages */ -bio_set_flag (bio,BIO_PAGE_REFFED ); +if (dio->need_unpin) +bio_set_flag (bio,BIO_PAGE_PINNED ); sdio->bio = bio; sdio->logical_offset_in_bio = sdio->cur_page_fs_offset; }
Quoted 41 lines · David Howells
Fix
dio_bio_alloc()to setBIO_PAGE_PINNED, notBIO_PAGE_REFFED, so that the bio code unpins the pinned pages rather than putting a ref on them.The issue was causing:
WARNING: CPU: 6 PID: 2220 at mm/gup.c:76 try_get_folioThis can be caused by creating a file on a loopback UDF filesystem, opening it
O_DIRECTand making two writes to it from the same source buffer.Fixes 1ccf164ec866 ("block: Use iov_iter_extract_pages() and page pinning in direct-io.c")Reported-by kernel test robot <[email protected]>Signed-off-by David Howells <[email protected]>cc Christoph Hellwig <[email protected]>cc David Hildenbrand <[email protected]>cc Andrew Morton <[email protected]>cc Jens Axboe <[email protected]>cc Al Viro <[email protected]>cc Matthew Wilcox <[email protected]>cc Jan Kara <[email protected]>cc Jeff Layton <[email protected]>cc Jason Gunthorpe <[email protected]>cc Logan Gunthorpe <[email protected]>cc Hillf Danton <[email protected]>cc Christian Brauner <[email protected]>cc Linus Torvalds <[email protected]>--- fs/direct-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/direct-io.c +0
-0
fs/direct-io.c dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, · line 417
Quoted 3 lines
fs/direct-io.c +0
-0@@ -415,7 +415,8 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio,else bio->bi_end_io = dio_bio_end_io;/* for now require references for all pages */
Does the comment still hold?
Quoted 7 lines
fs/direct-io.c +2
-1-bio_set_flag (bio,BIO_PAGE_REFFED ); +if (dio->need_unpin) +bio_set_flag (bio,BIO_PAGE_PINNED ); sdio->bio = bio; sdio->logical_offset_in_bio = sdio->cur_page_fs_offset; }
Signature · 3 lines
Cheers, David / dhildenb
Quoted 3 lines · David Hildenbrand
Quoted 1 line
/* for now require references for all pages */
Does the comment still hold?
Actually, no.
David
Okay, it isn't this. The problem appears to be that __blockdev_direct_IO() calls dio_cleanup() twice if do_direct_IO() fails.
David
static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio) {
- while (sdio->head < sdio->tail)
- put_page(dio->pages[sdio->head++]);
+ if (dio->is_pinned)
+ unpin_user_pages(dio->pages + sdio->head,
+ sdio->tail - sdio->head);
}
/*
Meh. It's obvious. Need to advance head.
David