From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757573Ab0EFKC3 (ORCPT ); Thu, 6 May 2010 06:02:29 -0400 Received: from gir.skynet.ie ([193.1.99.77]:34783 "EHLO gir.skynet.ie" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755636Ab0EFKC1 (ORCPT ); Thu, 6 May 2010 06:02:27 -0400 Date: Thu, 6 May 2010 11:02:08 +0100 From: Mel Gorman To: Linus Torvalds Cc: Andrew Morton , Linux-MM , LKML , Minchan Kim , KAMEZAWA Hiroyuki , Christoph Lameter , Andrea Arcangeli , Rik van Riel Subject: Re: [PATCH 1/2] mm,migration: Prevent rmap_walk_[anon|ksm] seeing the wrong VMA information Message-ID: <20100506100208.GB20979@csn.ul.ie> References: <1273065281-13334-1-git-send-email-mel@csn.ul.ie> <1273065281-13334-2-git-send-email-mel@csn.ul.ie> <20100505145620.GP20979@csn.ul.ie> <20100505175311.GU20979@csn.ul.ie> <20100506002255.GY20979@csn.ul.ie> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17+20080114 (2008-01-14) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 05, 2010 at 05:42:19PM -0700, Linus Torvalds wrote: > > > On Thu, 6 May 2010, Mel Gorman wrote: > > + /* > > + * Get the root anon_vma on the list by depending on the ordering > > + * of the same_vma list setup by __page_set_anon_rmap. Basically > > + * we are doing > > + * > > + * local anon_vma -> local vma -> deepest vma -> anon_vma > > + */ > > + avc = list_first_entry(&anon_vma->head, struct anon_vma_chain, same_anon_vma); > > + vma = avc->vma; > > + root_avc = list_entry(vma->anon_vma_chain.prev, struct anon_vma_chain, same_vma); > > + root_anon_vma = root_avc->anon_vma; > > + if (!root_anon_vma) { > > + /* XXX: Can this happen? Don't think so but get confirmation */ > > + WARN_ON_ONCE(1); > > + return anon_vma; > > + } > > No, that can't happen. If you find an avc struct, it _will_ have a > anon_vma pointer. So there's no point in testing for NULL. If some bug > happens, you're much better off with the oops than with the warning. > Good. If this returns NULL, it should oops when spin_lock(NULL->lock) is called. > > + /* Get the lock of the root anon_vma */ > > + if (anon_vma != root_anon_vma) { > > + /* > > + * XXX: This doesn't seem safe. What prevents root_anon_vma > > + * getting freed from underneath us? Not much but if > > + * we take the second lock first, there is a deadlock > > + * possibility if there are multiple callers of rmap_walk > > + */ > > + spin_unlock(&anon_vma->lock); > > + spin_lock(&root_anon_vma->lock); > > + } > > What makes this ok is the fact that it must be running under the RCU read > lock, and anon_vma's thus cannot be released. This is very subtle in itself. RCU guarantees that the anon_vma exists but does it guarantee that it's the same one we expect and that it hasn't been freed and reused? > My version of the code made > that explicit. Yours does not, and doesn't even have comments about the > fact that it needs to be called RCU read-locked. Tssk, tssk. > I added a comment. > Please don't just assume locking. Either lock it, or say "this must be > called with so-and-so held". Not just a silent "this would be buggy if > anybody ever called it without the RCU lock". > Sure. It was an oversight when merging what I had with what you posted up. -- Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab