Received: by 10.223.185.116 with SMTP id b49csp4811447wrg; Wed, 7 Mar 2018 01:09:07 -0800 (PST) X-Google-Smtp-Source: AG47ELvQnRdnIIkqc93iMTJqrnDVGEL074q9oceRTku/HwwydOcDVKwabgQqroDbUiLW7QN7N5CU X-Received: by 2002:a17:902:595d:: with SMTP id e29-v6mr19796500plj.189.1520413746898; Wed, 07 Mar 2018 01:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520413746; cv=none; d=google.com; s=arc-20160816; b=x2Pfx/w2SuFPsGRa8F4FzLTzFgwjzQGFfQ5BSj2WVcgH7c5piG7vAWMSzD4t0bzLcX ceBszVIhO2+UIdXgwVlgYcx164Ish0hDfNt7GKDhrSj2mH592Ta6GmN6OehDgEojulC0 puAJajSyrLeZiaXI2Mm+znHW77392Tp1w6COwHQIZNIcH1Sv2tBFNWp4ZG+QcMgw49D1 4kNvy6VZDh4+KacuhKmqxu64Ekby5udWog6L0l//nwKx4iL1uBss17Jitc9W4wEavVqI pf2NISbFoGeFi2zaeegBCAdvRes7VaaFCCgeBfdDxswfMb5bohkscYTpHFkSes0lZ8ak eOeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:arc-authentication-results; bh=DNaA6HVpGhFBpWD63GvqXGsZj2ZWTSjNuZyrcXVIM5o=; b=GXKpCE8fnszSKextGzwNyMLbdrcjWjJ63gxZ8S2cJ6w2od3pdLEcMSijDnNk43vJFY JhLShf3paT2YXa9ri1iRaGwUCOeRE3mo5br6rGsDH51ZynvTxTdC3RXOD00IAZ0rANzg kydST3xzaK1BQtv6oEFFkOVAnHk+/ScY7Ek+HisRLLCA4KnRnmZu1wqQTaHPg1pKJwgj jmvWqfvnISgIrR1W8B6bKHqysyI+puVttNnDvpMx4kJ6VtN5ZChHADoE7kllFrUlH9zU laXe7oGS6k9vqGYV9MrD9GY9f1+hk6MeE0qkHfbpxfLFQHwJn7izyaH9zyBDl7T+7fNx Q7PA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12-v6si1945029pli.373.2018.03.07.01.08.52; Wed, 07 Mar 2018 01:09:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751263AbeCGJHG (ORCPT + 99 others); Wed, 7 Mar 2018 04:07:06 -0500 Received: from mx2.suse.de ([195.135.220.15]:55156 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751071AbeCGJHD (ORCPT ); Wed, 7 Mar 2018 04:07:03 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 993F9AD38; Wed, 7 Mar 2018 09:07:01 +0000 (UTC) Subject: Re: [PATCH v2] mm: might_sleep warning To: Pavel Tatashin , steven.sistare@oracle.com, daniel.m.jordan@oracle.com, m.mizuma@jp.fujitsu.com, akpm@linux-foundation.org, mhocko@suse.com, catalin.marinas@arm.com, takahiro.akashi@linaro.org, gi-oh.kim@profitbricks.com, heiko.carstens@de.ibm.com, baiyaowei@cmss.chinamobile.com, richard.weiyang@gmail.com, paul.burton@mips.com, miles.chen@mediatek.com, mgorman@suse.de, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20180306224004.25150-1-pasha.tatashin@oracle.com> From: Vlastimil Babka Message-ID: <33e3a3ff-0318-1a07-3c57-6be638046c87@suse.cz> Date: Wed, 7 Mar 2018 10:06:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180306224004.25150-1-pasha.tatashin@oracle.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/06/2018 11:40 PM, Pavel Tatashin wrote: > Robot reported this issue: > https://lkml.org/lkml/2018/2/27/851 > > That is introduced by: > mm: initialize pages on demand during boot > > The problem is caused by changing static branch value within spin lock. > Spin lock disables preemption, and changing static branch value takes > mutex lock in its path, and thus may sleep. > > The fix is to add another boolean variable to avoid the need to change > static branch within spinlock. > > Also, as noticed by Andrew, change spin_lock to spin_lock_irq, in order > to disable interrupts and avoid possible deadlock with > deferred_grow_zone(). > > Signed-off-by: Pavel Tatashin > --- > mm/page_alloc.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index b337a026007c..5df1ca40a2ff 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -1579,6 +1579,7 @@ static int __init deferred_init_memmap(void *data) > * page_alloc_init_late() soon after smp_init() is complete. > */ > static __initdata DEFINE_SPINLOCK(deferred_zone_grow_lock); > +static bool deferred_zone_grow __initdata = true; > static DEFINE_STATIC_KEY_TRUE(deferred_pages); > > /* > @@ -1616,7 +1617,7 @@ deferred_grow_zone(struct zone *zone, unsigned int order) > * Bail if we raced with another thread that disabled on demand > * initialization. > */ > - if (!static_branch_unlikely(&deferred_pages)) { > + if (!static_branch_unlikely(&deferred_pages) || !deferred_zone_grow) { > spin_unlock_irqrestore(&deferred_zone_grow_lock, flags); > return false; > } > @@ -1683,10 +1684,15 @@ void __init page_alloc_init_late(void) > /* > * We are about to initialize the rest of deferred pages, permanently > * disable on-demand struct page initialization. Hi, I've noticed that this function first disables the on-demand initialization, and then runs the kthreads. Doesn't that leave a window where allocations can fail? The chances are probably small, but I think it would be better to avoid it completely, rare failures suck. Fixing that probably means rethinking the whole synchronization more dramatically though :/ Vlastimil > + * > + * Note: it is prohibited to modify static branches in non-preemptible > + * context. Since, spin_lock() disables preemption, we must use an > + * extra boolean deferred_zone_grow. > */ > - spin_lock(&deferred_zone_grow_lock); > + spin_lock_irq(&deferred_zone_grow_lock); > + deferred_zone_grow = false; > + spin_unlock_irq(&deferred_zone_grow_lock); > static_branch_disable(&deferred_pages); > - spin_unlock(&deferred_zone_grow_lock); > > /* There will be num_node_state(N_MEMORY) threads */ > atomic_set(&pgdat_init_n_undone, num_node_state(N_MEMORY)); >