loop, zloop: fix dma_alignment for large or unreported limits
Subsystems (2)
PATCH 1/1 loop, zloop: fix dma_alignment for large or unreported limits
From: Keith Busch <[email protected]>
A file system sets STATX_DIOALIGN with zeroed alignments when the file can't be used for direct I/O. The zero underflowed to UINT_MAX and triggered a queue limits validation warning. Fall back to the block device's limits when dio_mem_align isn't reported.
A file system with a block size larger than PAGE_SIZE may also report a memory alignment that can't be expressed as a queue limit. File systems fall back to buffered I/O for requests that don't meet their alignment, so cap the reported limit to the largest possible value.
--- drivers/block/loop.c | 8 +++++--- drivers/block/zloop.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-)
drivers/block/loop.c +5 -3
@@ -458,12 +458,14 @@ static void loop_update_dio_alignment(struct loop_device *lo)* Use the dio alignment of the file system if provided. The incomoing * request's bio_vec is forwarded to the backing file unchanged, so its * required memory alignment becomes the device's dma_alignment when -* used for direct-io. +* used for direct-io. The file system reports zeroed alignments if the +* file can't be used for direct-io at all, so fall back to the block +* device limits in that case. */ if (!vfs_getattr (&file->f_path, &st,STATX_DIOALIGN ,0 ) && - (st.result_mask &STATX_DIOALIGN )) { + (st.result_mask &STATX_DIOALIGN ) && st.dio_mem_align) { lo->lo_min_dio_size = st.dio_offset_align; - lo->lo_dio_mem_align = st.dio_mem_align -1 ; + lo->lo_dio_mem_align =min (st.dio_mem_align -1 ,PAGE_SIZE -1 );return ; }
drivers/block/zloop.c +5 -3
@@ -1042,12 +1042,14 @@ static int zloop_get_block_size(struct zloop_device *zlo,* Use the dio alignment of the file system if provided. The incoming * request's bio_vec is forwarded to the backing file unchanged, so its * required memory alignment becomes the device's dma_alignment when -* used for direct-io. +* used for direct-io. The file system reports zeroed alignments if the +* file can't be used for direct-io at all, so fall back to the block +* device limits in that case. */ if (!vfs_getattr (&zone->file->f_path, &st,STATX_DIOALIGN ,0 ) && - (st.result_mask &STATX_DIOALIGN )) { + (st.result_mask &STATX_DIOALIGN ) && st.dio_mem_align) { zlo->block_size = st.dio_offset_align; - zlo->dio_mem_align = st.dio_mem_align -1 ; + zlo->dio_mem_align =min (st.dio_mem_align -1 ,PAGE_SIZE -1 ); }else if (sb_bdev) { zlo->block_size =bdev_physical_block_size (sb_bdev); zlo->dio_mem_align =bdev_dma_alignment (sb_bdev);
Signature · 1 line
2.53.0-Meta
Quoted 11 lines · Keith Busch
From: Keith Busch <[email protected]>
A file system sets
STATX_DIOALIGNwith zeroed alignments when the file can't be used for direct I/O. The zero underflowed toUINT_MAXand triggered a queue limits validation warning. Fall back to the block device's limits whendio_mem_alignisn't reported.A file system with a block size larger than
PAGE_SIZEmay also report a memory alignment that can't be expressed as a queue limit. File systems fall back to buffered I/O for requests that don't meet their alignment, so cap the reported limit to the largest possible value.
In general having separate patches per driver would seem nicer than a batched up one like this, but the changes do look good:
Quoted 11 lines · Keith Busch
A file system sets
STATX_DIOALIGNwith zeroed alignments when the file can't be used for direct I/O. The zero underflowed toUINT_MAXand triggered a queue limits validation warning. Fall back to the block device's limits whendio_mem_alignisn't reported.A file system with a block size larger than
PAGE_SIZEmay also report a memory alignment that can't be expressed as a queue limit. File systems fall back to buffered I/O for requests that don't meet their alignment, so cap the reported limit to the largest possible value.[...]
Applied, thanks!
[1/1] loop, zloop: fix dma_alignment for large or unreported limits
commit: e52349a5ea6a74d46dfb703fcb64e08b5af28e8c
Best regards,
Signature · 1 line
Jens Axboe