lkml.org 
[lkml]   [2016]   [Jan]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4] futex: Remove requirement for lock_page in get_futex_key
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.

\
 
 \ /
  Last update: 2016-01-29 20:01    [W:0.042 / U:0.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site