From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754055AbeCFVVc (ORCPT ); Tue, 6 Mar 2018 16:21:32 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42092 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753071AbeCFVVb (ORCPT ); Tue, 6 Mar 2018 16:21:31 -0500 Date: Tue, 6 Mar 2018 13:21:29 -0800 From: Andrew Morton To: Pavel Tatashin Cc: Steven Sistare , Daniel Jordan , Masayoshi Mizuma , Michal Hocko , Catalin Marinas , AKASHI Takahiro , Gioh Kim , Heiko Carstens , Yaowei Bai , Wei Yang , Paul Burton , Miles Chen , Vlastimil Babka , Mel Gorman , Johannes Weiner , LKML , linux-mm@kvack.org Subject: Re: [PATCH] mm: might_sleep warning Message-Id: <20180306132129.45b395d9732b6360fa0b600d@linux-foundation.org> In-Reply-To: References: <20180306192022.28289-1-pasha.tatashin@oracle.com> <20180306123655.957e5b6b20b200505544ea7a@linux-foundation.org> <20180306125604.c394a25a50cae0e36c546855@linux-foundation.org> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; 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 Tue, 6 Mar 2018 16:04:06 -0500 Pavel Tatashin wrote: > > > > > spin_lock(&deferred_zone_grow_lock); > > > > > - static_branch_disable(&deferred_pages); > > > > > + deferred_zone_grow = false; > > > > > spin_unlock(&deferred_zone_grow_lock); > > > > > + static_branch_disable(&deferred_pages); > > > > > > > > > > /* There will be num_node_state(N_MEMORY) threads */ > > > > > atomic_set(&pgdat_init_n_undone, num_node_state(N_MEMORY)); > > > > > > > > Kinda ugly, but I can see the logic behind the decisions. > > > > > > > > Can we instead turn deferred_zone_grow_lock into a mutex? > > > > (top-posting repaired. Please don't top-post). > > > > > [CCed everyone] > > > > > > Hi Andrew, > > > > > > I afraid we cannot change this spinlock to mutex > > > because deferred_grow_zone() might be called from an interrupt context if > > > interrupt thread needs to allocate memory. > > > > > > > OK. But if deferred_grow_zone() can be called from interrupt then > > page_alloc_init_late() should be using spin_lock_irq(), shouldn't it? > > I'm surprised that lockdep didn't detect that. > > No, page_alloc_init_late() cannot be called from interrupt, it is > called straight from: > kernel_init_freeable(). But, I believe deferred_grow_zone(): can be called: > > get_page_from_freelist() > _deferred_grow_zone() > deferred_grow_zone() That's why page_alloc_init_late() needs spin_lock_irq(). If a CPU is holding deferred_zone_grow_lock with enabled interrupts and an interrupt comes in on that CPU and the CPU runs deferred_grow_zone() in its interrupt handler, we deadlock. lockdep knows about this bug and should have reported it.