From: Keith Busch <kbusch@kernel.org>
The block layer checks all the segments for validity later, so no need
for an early check. Just reduce it to a simple position and total length
and defer the segment checks to the block layer.
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
block/fops.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/fops.c b/block/fops.c
index 82451ac8ff25d..820902cf10730 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -38,8 +38,8 @@ static blk_opf_t dio_bio_write_op(struct kiocb *iocb)
static bool blkdev_dio_invalid(struct block_device *bdev, struct kiocb *iocb,
struct iov_iter *iter)
{
- return iocb->ki_pos & (bdev_logical_block_size(bdev) - 1) ||
- !bdev_iter_is_aligned(bdev, iter);
+ return (iocb->ki_pos | iov_iter_count(iter)) &
+ (bdev_logical_block_size(bdev) - 1);
}
#define DIO_INLINE_BIO_VECS 4
--
2.47.3
On 8/2/25 01:47, Keith Busch wrote: > From: Keith Busch <kbusch@kernel.org> > > The block layer checks all the segments for validity later, so no need > for an early check. Just reduce it to a simple position and total length > and defer the segment checks to the block layer. > > Signed-off-by: Keith Busch <kbusch@kernel.org> > --- > block/fops.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/block/fops.c b/block/fops.c > index 82451ac8ff25d..820902cf10730 100644 > --- a/block/fops.c > +++ b/block/fops.c > @@ -38,8 +38,8 @@ static blk_opf_t dio_bio_write_op(struct kiocb *iocb) > static bool blkdev_dio_invalid(struct block_device *bdev, struct kiocb *iocb, > struct iov_iter *iter) > { > - return iocb->ki_pos & (bdev_logical_block_size(bdev) - 1) || > - !bdev_iter_is_aligned(bdev, iter); > + return (iocb->ki_pos | iov_iter_count(iter)) & > + (bdev_logical_block_size(bdev) - 1); Bitwise or? Sure? > } > > #define DIO_INLINE_BIO_VECS 4 Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
On Mon, Aug 04, 2025 at 08:55:36AM +0200, Hannes Reinecke wrote: > On 8/2/25 01:47, Keith Busch wrote: > > static bool blkdev_dio_invalid(struct block_device *bdev, struct kiocb *iocb, > > struct iov_iter *iter) > > { > > - return iocb->ki_pos & (bdev_logical_block_size(bdev) - 1) || > > - !bdev_iter_is_aligned(bdev, iter); > > + return (iocb->ki_pos | iov_iter_count(iter)) & > > + (bdev_logical_block_size(bdev) - 1); > > Bitwise or? Sure? Yep, this is correct. We need to return an error if either the size or offset are not aligned to the block size. "Or"ing the two together gets us a single check against the logical block size mask instead of doing each individually.
On 8/4/25 19:11, Keith Busch wrote: > On Mon, Aug 04, 2025 at 08:55:36AM +0200, Hannes Reinecke wrote: >> On 8/2/25 01:47, Keith Busch wrote: >>> static bool blkdev_dio_invalid(struct block_device *bdev, struct kiocb *iocb, >>> struct iov_iter *iter) >>> { >>> - return iocb->ki_pos & (bdev_logical_block_size(bdev) - 1) || >>> - !bdev_iter_is_aligned(bdev, iter); >>> + return (iocb->ki_pos | iov_iter_count(iter)) & >>> + (bdev_logical_block_size(bdev) - 1); >> >> Bitwise or? Sure? > > Yep, this is correct. We need to return an error if either the size or > offset are not aligned to the block size. "Or"ing the two together gets > us a single check against the logical block size mask instead of doing > each individually. Oh, my. Wasn't aware that we're running an obfuscated C-contest ... Anyway. Reviewed-by: Hannes Reinecke <hare@suse.de> Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
© 2016 - 2025 Red Hat, Inc.