Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751502AbaLZHUm (ORCPT ); Fri, 26 Dec 2014 02:20:42 -0500 Received: from mail-qc0-f182.google.com ([209.85.216.182]:51496 "EHLO mail-qc0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751197AbaLZHUi (ORCPT ); Fri, 26 Dec 2014 02:20:38 -0500 Date: Fri, 26 Dec 2014 02:20:32 -0500 From: Jerome Glisse To: Haggai Eran Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , joro@8bytes.org, Mel Gorman , "H. Peter Anvin" , Peter Zijlstra , Andrea Arcangeli , Johannes Weiner , Larry Woodman , Rik van Riel , Dave Airlie , Brendan Conoboy , Joe Donohue , Duncan Poole , Sherry Cheung , Subhash Gutti , John Hubbard , Mark Hairgrove , Lucien Dunning , Cameron Buschardt , Arvind Gopalakrishnan , Shachar Raindel , Liran Liss , Roland Dreier , Ben Sander , Greg Stoner , John Bridgman , Michael Mantor , Paul Blinzer , Laurent Morichetti , Alexander Deucher , Oded Gabbay , =?iso-8859-1?B?Suly9G1l?= Glisse Subject: Re: [PATCH 2/7] mmu_notifier: keep track of active invalidation ranges v2 Message-ID: <20141226071112.GA4408@gmail.com> References: <1419266940-5440-1-git-send-email-j.glisse@gmail.com> <1419266940-5440-3-git-send-email-j.glisse@gmail.com> <549BCAF8.1070500@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <549BCAF8.1070500@mellanox.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 25, 2014 at 10:29:44AM +0200, Haggai Eran wrote: > On 22/12/2014 18:48, j.glisse@gmail.com wrote: > > static inline void mmu_notifier_invalidate_range_start(struct mm_struct *mm, > > - unsigned long start, > > - unsigned long end, > > - enum mmu_event event) > > + struct mmu_notifier_range *range) > > { > > + /* > > + * Initialize list no matter what in case a mmu_notifier register after > > + * a range_start but before matching range_end. > > + */ > > + INIT_LIST_HEAD(&range->list); > > I don't see how can an mmu_notifier register after a range_start but > before a matching range_end. The mmu_notifier registration locks all mm > locks, and that should prevent any invalidation from running, right? File invalidation (like truncation) can lead to this case. > > > if (mm_has_notifiers(mm)) > > - __mmu_notifier_invalidate_range_start(mm, start, end, event); > > + __mmu_notifier_invalidate_range_start(mm, range); > > } > > ... > > > void __mmu_notifier_invalidate_range_start(struct mm_struct *mm, > > - unsigned long start, > > - unsigned long end, > > - enum mmu_event event) > > + struct mmu_notifier_range *range) > > > > { > > struct mmu_notifier *mn; > > @@ -185,21 +183,36 @@ void __mmu_notifier_invalidate_range_start(struct mm_struct *mm, > > id = srcu_read_lock(&srcu); > > hlist_for_each_entry_rcu(mn, &mm->mmu_notifier_mm->list, hlist) { > > if (mn->ops->invalidate_range_start) > > - mn->ops->invalidate_range_start(mn, mm, start, > > - end, event); > > + mn->ops->invalidate_range_start(mn, mm, range); > > } > > srcu_read_unlock(&srcu, id); > > + > > + /* > > + * This must happen after the callback so that subsystem can block on > > + * new invalidation range to synchronize itself. > > + */ > > + spin_lock(&mm->mmu_notifier_mm->lock); > > + list_add_tail(&range->list, &mm->mmu_notifier_mm->ranges); > > + mm->mmu_notifier_mm->nranges++; > > + spin_unlock(&mm->mmu_notifier_mm->lock); > > } > > EXPORT_SYMBOL_GPL(__mmu_notifier_invalidate_range_start); > > Don't you have a race here because you add the range struct after the > callback? > > ------------------------------------------------------------------------- > Thread A | Thread B > ------------------------------------------------------------------------- > call mmu notifier callback | > clear SPTE | > | device page fault > | mmu_notifier_range_is_valid returns true > | install new SPTE > add event struct to list | > mm clears/modifies the PTE | > ------------------------------------------------------------------------- > > So we are left with different entries in the host page table and the > secondary page table. > > I would think you'd want the event struct to be added to the list before > the callback is run. > Yes you right, but the comment i left trigger memory that i did that on purpose a one point probably with a different synch mecanism inside hmm. I will try to medidate a bit see if i can bring back memory why i did it that way in respect to previous design. In all case i will respin with that order modified. Can i add you review by after doing so ? Cheers, J?r?me -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/