mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Matthew Wilcox <willy@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
	Konstantin Khlebnikov <khlebnikov@openvz.org>,
	Hugh Dickins <hughd@google.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: Bug in radix tree gang lookup?
Date: Tue, 26 Jan 2016 20:04:02 -0800 (PST)	[thread overview]
Message-ID: <alpine.LSU.2.11.1601261955120.3338@eggly.anvils> (raw)
In-Reply-To: <20160122134012.GC2948@linux.intel.com>

On Fri, 22 Jan 2016, Matthew Wilcox wrote:
> 
> I think there's a race in radix_tree_gang_lookup() (and
> related functions).  I was trying to understand why we need the
> 'indirect_to_ptr()' call here:
> 
>         radix_tree_for_each_slot(slot, root, &iter, first_index) {
>                 results[ret] = indirect_to_ptr(rcu_dereference_raw(*slot));
>                 if (!results[ret])
>                         continue;
>                 if (++ret == max_items)
>                         break;
>         }
> 
> The slots returned are supposed to be leaf nodes, so why would they ever
> have the indirect bit set?
> 
> The only two cases I can think of where we'd see a slot with the indirect
> bit set is if we're calling radix_tree_gang_lookup() under the RCU read
> lock and simultaneously growing / shrinking the tree.  When the tree
> transitions from height 0 to height 1, the 'slot' that was returned is now
> an internal pointer, so simply knocking off the 'indirect_to_ptr()' bit
> is the wrong thing to do; instead of returning a struct page pointer, we
> return a pointer to a radix_tree_node, which isn't good.  When shrinking
> the tree from height 1 to height 0, we may end up looking at a pointer
> in to-be-freed memory, but it's still a valid pointer to a struct page,
> so I think we're OK in the shrink case.
> 
> The lockless page cache shows how to handle this correctly; when we
> see an indirect bit come back in a slot, we should retry the lookup.
> I think that's the right thing to do in this case, but I'd like someone
> to check my reasoning before I propose a patch.

I think you're right, in all you say above.  And I think the last
paragraph of comment above the one-level-of-indirection-different
radix_tree_gang_lookup_slot() is making the same point, though its
language hasn't been updated for years (it ought to say something
like "radix_tree_deref_retry may require a retry").

Hugh

      reply	other threads:[~2016-01-27  4:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-22 13:40 Matthew Wilcox
2016-01-27  4:04 ` Hugh Dickins [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=alpine.LSU.2.11.1601261955120.3338@eggly.anvils \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=khlebnikov@openvz.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=willy@linux.intel.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

all inboxes | Powered by JetHome®