-----Original Message----- From: Matthew Wilcox [mailto:willy@xxxxxxxxxxxxx] Sent: Tuesday, December 05, 2017 5:19 PM To: Kasiviswanathan, Harish <Harish.Kasiviswanathan@xxxxxxx> Cc: guaneryu@xxxxxxxxx; linux-fsdevel@xxxxxxxxxxxxxxx; Kuehling, Felix <Felix.Kuehling@xxxxxxx> Subject: Re: [PATCH v2] direct-io: Fix unsigned comparison overflow On Tue, Dec 05, 2017 at 04:40:27PM -0500, Harish Kasiviswanathan wrote: > create = dio->op == REQ_OP_WRITE; > - if (dio->flags & DIO_SKIP_HOLES) { > + if (dio->flags & DIO_SKIP_HOLES && > + i_size_read(dio->inode) > 0) { > if (fs_startblk <= ((i_size_read(dio->inode) - 1) >> > i_blkbits)) i_size_read() isn't cheap on 32-bit SMP ... do we actually need to sample it at all here, or is it enough to use the i_size that was sampled earlier? IOW: [HK]: Thanks Matthew. I don't know enough about ext4 subsystem to comment if dio->i_size could be used here. create = dio->op == REQ_OP_WRITE; - if (dio->flags & DIO_SKIP_HOLES) { - if (fs_startblk <= ((i_size_read(dio->inode) - 1) >> - i_blkbits)) + if (dio->flags & DIO_SKIP_HOLES && dio->i_size) { + if (fs_startblk <= (dio->i_size - 1) >> i_blkbits)) Another possibility would be to tweak the comparison slightly ... if (dio->flags & DIO_SKIP_HOLES) { - if (fs_startblk <= ((i_size_read(dio->inode) - 1) >> - i_blkbits)) + if (fs_startblk < ((i_size_read(dio->inode) + + (1UL << i_blkbits) - 1) >> i_blkbits)) [HK]: I like this solution. Achieves the same functionality. If no one else has an objection then we can go with this solution. Or we could use a temporary variable to avoid reading i_size twice.