Skip to contentSkip to conversation

block: Fix dio_cleanup() to advance the head index

PATCH Applied David Howells 4 participants 4 messages Jun 13, 2023 – Jun 14, 2023

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

PATCH 1/1 block: Fix dio_cleanup() to advance the head index

Fix dio_bio_cleanup() to advance the head index into the list of pages past the pages it has released, as __blockdev_direct_IO() will call it twice if do_direct_IO() fails.

The issue was causing:

        WARNING: CPU: 6 PID: 2220 at mm/gup.c:76 try_get_folio

This can be triggered by setting up a clean pair of UDF filesystems on loopback devices and running the generic/451 xfstest with them as the scratch and test partitions. Something like the following:

fallocate /mnt2/udf_scratch -l 1G
fallocate /mnt2/udf_test -l 1G
mknod /dev/lo0 b 7 0
mknod /dev/lo1 b 7 1
losetup lo0 /mnt2/udf_scratch
losetup lo1 /mnt2/udf_test
mkfs -t udf /dev/lo0
mkfs -t udf /dev/lo1
cd xfstests
./check generic/451

with xfstests configured by putting the following into local.config:

export FSTYP=udf
export DISABLE_UDF_TEST=1
export TEST_DEV=/dev/lo1
export TEST_DIR=/xfstest.test
export SCRATCH_DEV=/dev/lo0
export SCRATCH_MNT=/xfstest.scratch

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]>
---
 fs/direct-io.c |    1 +
 1 file changed, 1 insertion(+)
fs/direct-io.c +1 -0
index 0643f1bb4b59..2ceb378b93c0 100644
@@ -459,6 +459,7 @@ static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio)
 	if (dio->is_pinned)
 		unpin_user_pages(dio->pages + sdio->head,
 				 sdio->tail - sdio->head);
+	sdio->head = sdio->tail;
 }
 
 /*
Reviewed-by on v1 1/1
#1 lore raw

fs/direct-io.c static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio) · line 462

Quoted 7 lines · David Howells
fs/direct-io.c +1 -0
@@ -459,6 +459,7 @@ static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio)
 	if (dio->is_pinned)
 		unpin_user_pages(dio->pages + sdio->head,
 				 sdio->tail - sdio->head);
+	sdio->head = sdio->tail;

So looking at the original patch, it does:

- 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);

so yes, we're this looks correct:

Reviewed-by on v1 1/1
#2 lore raw
In reply to David Howells
Quoted 64 lines · David Howells

Fix dio_bio_cleanup() to advance the head index into the list of pages past the pages it has released, as __blockdev_direct_IO() will call it twice if do_direct_IO() fails.

The issue was causing:

         WARNING: CPU: 6 PID: 2220 at mm/gup.c:76 try_get_folio

This can be triggered by setting up a clean pair of UDF filesystems on loopback devices and running the generic/451 xfstest with them as the scratch and test partitions. Something like the following:

fallocate /mnt2/udf_scratch -l 1G
fallocate /mnt2/udf_test -l 1G
mknod /dev/lo0 b 7 0
mknod /dev/lo1 b 7 1
losetup lo0 /mnt2/udf_scratch
losetup lo1 /mnt2/udf_test
mkfs -t udf /dev/lo0
mkfs -t udf /dev/lo1
cd xfstests
./check generic/451

with xfstests configured by putting the following into local.config:

export FSTYP=udf
export DISABLE_UDF_TEST=1
export TEST_DEV=/dev/lo1
export TEST_DIR=/xfstest.test
export SCRATCH_DEV=/dev/lo0
export SCRATCH_MNT=/xfstest.scratch

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]>
---
  fs/direct-io.c |    1 +
  1 file changed, 1 insertion(+)
fs/direct-io.c +0 -0
index 0643f1bb4b59..2ceb378b93c0 100644

fs/direct-io.c static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio) · line 465

Quoted 7 lines
fs/direct-io.c +1 -0
@@ -459,6 +459,7 @@ static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio)
  	if (dio->is_pinned)
  		unpin_user_pages(dio->pages + sdio->head,
  				 sdio->tail - sdio->head);
+	sdio->head = sdio->tail;
  }
 
  /*
Signature · 3 lines
Cheers,

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

Fix dio_bio_cleanup() to advance the head index into the list of pages past the pages it has released, as __blockdev_direct_IO() will call it twice if do_direct_IO() fails.

The issue was causing:

[...]

Applied, thanks!

[1/1] block: Fix dio_cleanup() to advance the head index

      commit: d44c404207831dfe3b301ff479e964b77914488b

Best regards,

Signature · 1 line
Jens Axboe