From: Eryu Guan <guaneryu@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>,
linux-fsdevel@vger.kernel.org, Felix.Kuehling@amd.com
Subject: Re: [PATCH v2] direct-io: Fix unsigned comparison overflow
Date: Wed, 6 Dec 2017 23:51:29 +0800 [thread overview]
Message-ID: <20171206155129.GC7106@eguan.usersys.redhat.com> (raw)
In-Reply-To: <20171205221927.GG26021@bombadil.infradead.org>
On Tue, Dec 05, 2017 at 02:19:27PM -0800, Matthew Wilcox wrote:
> 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:
>
> 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))
I think using dio->i_size should be fine. I tested ext3/4 with LTP
(aio-)dio tests and fstests and didn't see any regression introduced
with this change.
Thanks,
Eryu
>
> 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))
>
> Or we could use a temporary variable to avoid reading i_size twice.
prev parent reply other threads:[~2017-12-06 15:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-05 21:40 [PATCH v2] direct-io: Fix unsigned comparison overflow Harish Kasiviswanathan
2017-12-05 22:19 ` Matthew Wilcox
2017-12-06 15:36 ` Kasiviswanathan, Harish
2017-12-06 15:51 ` Eryu Guan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171206155129.GC7106@eguan.usersys.redhat.com \
--to=guaneryu@gmail.com \
--cc=Felix.Kuehling@amd.com \
--cc=Harish.Kasiviswanathan@amd.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).