From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932327AbdESWAV (ORCPT ); Fri, 19 May 2017 18:00:21 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:34979 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932080AbdESWAU (ORCPT ); Fri, 19 May 2017 18:00:20 -0400 Date: Fri, 19 May 2017 15:00:10 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Xishi Qiu cc: Andrew Morton , Tejun Heo , Michal Hocko , Johannes Weiner , Mel Gorman , Michal Hocko , Vlastimil Babka , Minchan Kim , David Rientjes , Joonsoo Kim , aarcange@redhat.com, sumeet.keswani@hpe.com, Rik van Riel , Hugh Dickins , Linux MM , LKML , zhong jiang Subject: Re: mm, something wring in page_lock_anon_vma_read()? In-Reply-To: <591EBE71.7080402@huawei.com> Message-ID: References: <591D6D79.7030704@huawei.com> <591EB25C.9080901@huawei.com> <591EBE71.7080402@huawei.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 19 May 2017, Xishi Qiu wrote: > On 2017/5/19 16:52, Xishi Qiu wrote: > > On 2017/5/18 17:46, Xishi Qiu wrote: > > > >> Hi, my system triggers this bug, and the vmcore shows the anon_vma seems be freed. > >> The kernel is RHEL 7.2, and the bug is hard to reproduce, so I don't know if it > >> exists in mainline, any reply is welcome! > >> > > > > When we alloc anon_vma, we will init the value of anon_vma->root, > > so can we set anon_vma->root to NULL when calling > > anon_vma_free -> kmem_cache_free(anon_vma_cachep, anon_vma); > > > > anon_vma_free() > > ... > > anon_vma->root = NULL; > > kmem_cache_free(anon_vma_cachep, anon_vma); > > > > I find if we do this above, system boot failed, why? > > > > If anon_vma was freed, we should not to access the root_anon_vma, because it maybe also > freed(e.g. anon_vma == root_anon_vma), right? > > page_lock_anon_vma_read() > ... > anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON); > root_anon_vma = ACCESS_ONCE(anon_vma->root); > if (down_read_trylock(&root_anon_vma->rwsem)) { // it's not safe > ... > if (!atomic_inc_not_zero(&anon_vma->refcount)) { // check anon_vma was not freed > ... > anon_vma_lock_read(anon_vma); // it's safe > ... You're ignoring the rcu_read_lock() on entry to page_lock_anon_vma_read(), and the SLAB_DESTROY_BY_RCU (recently renamed SLAB_TYPESAFE_BY_RCU) nature of the anon_vma_cachep kmem cache. It is not safe to muck with anon_vma-> root in anon_vma_free(), others could still be looking at it. Hugh