From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751956AbdHCXLs (ORCPT ); Thu, 3 Aug 2017 19:11:48 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37516 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751754AbdHCXLr (ORCPT ); Thu, 3 Aug 2017 19:11:47 -0400 Date: Thu, 3 Aug 2017 16:11:46 -0700 From: Andrew Morton To: Cong Wang Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, Hugh Dickins , Linus Torvalds , "Kirill A . Shutemov" Subject: Re: [PATCH] mm: fix list corruptions on shmem shrinklist Message-Id: <20170803161146.4316d105e533a363a5597e64@linux-foundation.org> In-Reply-To: <20170803054630.18775-1-xiyou.wangcong@gmail.com> References: <20170803054630.18775-1-xiyou.wangcong@gmail.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2 Aug 2017 22:46:30 -0700 Cong Wang wrote: > We saw many list corruption warnings on shmem shrinklist: > > ... > > The problem is that shmem_unused_huge_shrink() moves entries > from the global sbinfo->shrinklist to its local lists and then > releases the spinlock. However, a parallel shmem_setattr() > could access one of these entries directly and add it back to > the global shrinklist if it is removed, with the spinlock held. > > The logic itself looks solid since an entry could be either > in a local list or the global list, otherwise it is removed > from one of them by list_del_init(). So probably the race > condition is that, one CPU is in the middle of INIT_LIST_HEAD() Where is this INIT_LIST_HEAD()? > but the other CPU calls list_empty() which returns true > too early then the following list_add_tail() sees a corrupted > entry. > > list_empty_careful() is designed to fix this situation. > I'm not sure I'm understanding this. AFAICT all the list operations to which you refer are synchronized under spin_lock(&sbinfo->shrinklist_lock)?