Skip to contentSkip to conversation

block: Fix dio_bio_alloc() to set BIO_PAGE_PINNED

PATCH In review David Howells 4 participants 6 messages Jun 12, 2023 – Jun 13, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

Fixes 1ccf164ec866 ("block: Use iov_iter_extract_pages() and page pinning in direct-io.c")
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]>

---

Notes:
ver #2)
- Remove comment on requiring references for all pages.

 fs/direct-io.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/direct-io.c +2 -2
index 14049204cac8..5d4c5be0fb41 100644
@@ -414,8 +414,8 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio,
 		bio->bi_end_io = dio_bio_end_aio;
 	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;
 }
Reviewed-by on v2 1/1
#2 lore raw
In reply to David Howells
Quoted 47 lines · David Howells

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.

Fixes 1ccf164ec866 ("block: Use iov_iter_extract_pages() and page pinning in direct-io.c")
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]>

---

Notes:
ver #2)
- Remove comment on requiring references for all pages.

  fs/direct-io.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/direct-io.c +0 -0
index 14049204cac8..5d4c5be0fb41 100644

fs/direct-io.c dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, · line 421

Quoted 10 lines
fs/direct-io.c +2 -2
@@ -414,8 +414,8 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio,
  		bio->bi_end_io = dio_bio_end_aio;
  	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;
  }
Signature · 3 lines
Cheers,

David / dhildenb
maintainer
#3 lore raw
In reply to David Howells
Quoted 10 lines · David Howells

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.

What is this against?

Signature · 1 line
Jens Axboe
#4 lore raw
Quoted 1 line · Jens Axboe

What is this against?

It's against the branch I posted. I should rebase it on your tree, but I'm in a conference at the moment, so that may have to wait till Thursday.

David

#5 lore raw
Quoted 3 lines · David Howells
Quoted 1 line

What is this against?

It's against the branch I posted.

Actually, it's not. It's against an old version of the patch on a different branch. The patches you have applied already have that change - so the issue must be something else:-/

David