From: Matthew Wilcox <willy@infradead.org>
To: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Cc: guaneryu@gmail.com, linux-fsdevel@vger.kernel.org,
Felix.Kuehling@amd.com
Subject: Re: [PATCH v2] direct-io: Fix unsigned comparison overflow
Date: Tue, 5 Dec 2017 14:19:27 -0800 [thread overview]
Message-ID: <20171205221927.GG26021@bombadil.infradead.org> (raw)
In-Reply-To: <1512510027-7101-1-git-send-email-Harish.Kasiviswanathan@amd.com>
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))
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.
next prev parent reply other threads:[~2017-12-05 22:19 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 [this message]
2017-12-06 15:36 ` Kasiviswanathan, Harish
2017-12-06 15:51 ` Eryu Guan
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=20171205221927.GG26021@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=Felix.Kuehling@amd.com \
--cc=Harish.Kasiviswanathan@amd.com \
--cc=guaneryu@gmail.com \
--cc=linux-fsdevel@vger.kernel.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).