All of lore.kernel.org
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@stgolabs.net>
To: Hugh Dickins <hughd@google.com>
Cc: Davidlohr Bueso <dbueso@suse.de>,
	Mel Gorman <mgorman@techsingularity.net>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Chris Mason <clm@fb.com>, Darren Hart <dvhart@linux.intel.com>,
	linux-kernel@vger.kernel.org, Mel Gorman <mgorman@suse.de>
Subject: Re: [PATCH v4] futex: Remove requirement for lock_page in get_futex_key
Date: Fri, 29 Jan 2016 10:35:57 -0800	[thread overview]
Message-ID: <20160129183557.GA16147@linux-uzut.site> (raw)
In-Reply-To: <alpine.LSU.2.11.1601271815460.1855@eggly.anvils>

On Wed, 27 Jan 2016, Hugh Dickins wrote:

>> +		 *
>> +		 * The RCU read lock is taken as the inode is finally freed
>> +		 * under RCU. If the mapping still matches expectations then the
>> +		 * mapping->host can be safely accessed as being a valid inode.
>> +		 */
>> +		rcu_read_lock();
>> +		if (READ_ONCE(page->mapping) != mapping ||
>> +		    !mapping->host) {
>
>If you're being as paranoid as all the WARN_ON_ONCEs hereabouts imply,
>then it would be better to do the inode = READ_ONCE(mapping->host)
>before checking !inode rather than !mapping->host.

Ok, it also reads a bit nicer than the above, which was simply avoiding
a load in the again case.

                rcu_read_lock();
                inode = READ_ONCE(mapping->host);

                if (!inode || READ_ONCE(page->mapping) != mapping)
                        rcu_read_unlock();
                        put_page(page);

                        goto again;
                }

[...]

>> +
>> +		/* Should be impossible but lets be paranoid for now */
>> +		if (WARN_ON_ONCE(inode->i_mapping != mapping)) {
>> +			err = -EFAULT;
>> +			iput(inode);
>> +			rcu_read_unlock();
>
>I think this is probably a WARN_ON_ONCE too many (but I'm error-prone on
>inode -> i_mapping -> host relationships, so ignore me); but if it's kept
>then I think you ought to do the iput(inode) after the rcu_read_unlock() -
>iput() can get into lots more work than you expect.

I'd rather keep some verbosity if something screws up here, albeit very rare, yes.
You make a good point about doing the inode cleanup while holding rcu, and moving
it down should be safe here even if the inode disappears after that iput (ie no
dereferencing). Secondly, we still hold reference to the inode by the time we drop
the rcu read lock, so thats safe too.

>
>Otherwise it appeared to be good to me (but years since I've been near here).

Thanks for taking a look at this. I'll send a v5 with your suggestions.

  reply	other threads:[~2016-01-29 18:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-23 17:14 [PATCH v4] futex: Remove requirement for lock_page in get_futex_key Davidlohr Bueso
2016-01-27 20:10 ` Thomas Gleixner
2016-01-28  3:02 ` Hugh Dickins
2016-01-29 18:35   ` Davidlohr Bueso [this message]
2016-01-29 18:46     ` Hugh Dickins

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=20160129183557.GA16147@linux-uzut.site \
    --to=dave@stgolabs.net \
    --cc=bigeasy@linutronix.de \
    --cc=clm@fb.com \
    --cc=dbueso@suse.de \
    --cc=dvhart@linux.intel.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mgorman@techsingularity.net \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.