public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: Theodore Ts'o <tytso@mit.edu>,
	Deepa Dinamani <deepa.kernel@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>
Cc: Wang Shilong <wshilong@ddn.com>,
	Wang Shilong <wangshilong1991@gmail.com>,
	"linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>,
	Shuichi Ihara <sihara@ddn.com>, Li Xi <lixi@ddn.com>,
	Jan Kara <jack@suse.cz>
Subject: Y2038 bug in ext4 recently_deleted() function
Date: Thu, 17 Aug 2017 15:51:41 -0600	[thread overview]
Message-ID: <BCA34CA8-FDDF-49FA-A5B4-9CCCEAC0C8D0@dilger.ca> (raw)
In-Reply-To: <20170817092153.GA14074@quack2.suse.cz>

[-- Attachment #1: Type: text/plain, Size: 1994 bytes --]

On Aug 17, 2017, at 3:21 AM, Jan Kara <jack@suse.cz> wrote:
> 
> On Thu 17-08-17 11:19:59, Jan Kara wrote:
>> Hi Shilong!
>> 
>> On Thu 17-08-17 06:23:26, Wang Shilong wrote:
>>>     thanks for good suggestion, just one question we could not hold lock
>>> with nojounal mode, how about something attached one?
>>> 
>>> please let me know if you have better taste for it, much appreciated!
>> 
>> Thanks for quickly updating the patch! Is the only reason why you cannot
>> hold the lock in the nojournal mode that sb_getblk() might sleep? The
>> attached patch should fix that so that you don't have to special-case the
>> nojournal mode anymore.
> 
> Forgot to attach the patch - here it is. Feel free to include it in your
> series as a preparatory patch.

Strange, I never even knew recently_deleted() existed, even though it was
added to the tree 4 years ago yesterday.  It looks like this is only used
with the no-journal code, which I don't really interact with.

One thing I did notice when looking at it is that there is a Y2038 bug in
recently_deleted(), as it is comparing 32-bit i_dtime directly with 64-bit
get_seconds().  To fix this, it would be possible to either use a wrapped
32-bit comparison, like time_after() for jiffies, something like:

	u32 now, dtime;

	/* assume dtime is within the past 30 years, see time_after() */
        now = get_seconds();
	if (dtime && (dtime - now < 0) && (dtime + recentcy - now < 0))
		ret = 1;

or use i_ctime_extra to implicitly extend i_dtime beyond 2038, something like:

	/* assume dtime epoch same as ctime, see EXT4_INODE_GET_XTIME() */
	dtime = le32_to_cpu(raw_inode->i_dtime);
	if (EXT4_INODE_SIZE(sb) > EXT4_GOOD_OLD_INODE_SIZE &&
	    offsetof(typeof(*raw_inode), i_ctime_extra) + 4 <=
	    EXT4_GOOD_OLD_INODE_SIZE + le32_to_cpu(raw_inode->i_extra_isize))
                dtime += (long)(le32_to_cpu(raw_inode->i_ctime_extra) &
				EXT4_EPOCH_MASK) << 32;

Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2017-08-17 21:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08  5:05 [PATCH v4] ext4: reduce lock contention in __ext4_new_inode Wang Shilong
2017-08-16 16:42 ` Jan Kara
2017-08-17  6:23   ` Wang Shilong
2017-08-17  9:19     ` Jan Kara
2017-08-17  9:21       ` Jan Kara
2017-08-17 21:51         ` Andreas Dilger [this message]
2017-08-18  1:23           ` Y2038 bug in ext4 recently_deleted() function Deepa Dinamani
2017-08-18  9:31             ` Arnd Bergmann
2017-08-18 15:38               ` Deepa Dinamani
2017-08-18 16:09                 ` Andreas Dilger
2017-08-22 15:18                   ` Arnd Bergmann
2017-08-22 16:20                     ` Andreas Dilger
2017-08-22 19:35                       ` Arnd Bergmann
2017-08-18 13:41             ` Theodore Ts'o

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=BCA34CA8-FDDF-49FA-A5B4-9CCCEAC0C8D0@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=arnd@arndb.de \
    --cc=deepa.kernel@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=lixi@ddn.com \
    --cc=sihara@ddn.com \
    --cc=tytso@mit.edu \
    --cc=wangshilong1991@gmail.com \
    --cc=wshilong@ddn.com \
    /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