Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4240678ybp; Mon, 7 Oct 2019 05:37:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgyLIrhLQJuHdZtmrk+yYT4npSy1c4PFWNDTz+TvFHeMZipaiEyBUgOto6mlz+weANUrcL X-Received: by 2002:a17:906:b2d9:: with SMTP id cf25mr16130059ejb.316.1570451854277; Mon, 07 Oct 2019 05:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570451854; cv=none; d=google.com; s=arc-20160816; b=DedBa2jQbMXs/deDNsBki+kJcG7Ba8B40NpyuE11TTBLUpp8WkoUwdoK1fbj/Oc/qK TDwf1pGikfZWbfxiTgZpWiD+aBA8HPU+H1sov4Bb8xrgbw0XkLgB7V+6UOVk88m2cXlM FLpPNK6AIDXXXJAPZlalNJSdisbic2X4v69L4gdO7idDIAHjlpo7tJHzTxbBCd6dsZjI 5RWgdaHqlPzRFAh3jAbeZZ6VThoWjjtQAyOoExs1Uew5nfeF8j+9Oth+/zu0IBikl3Q7 qpqoSjqrmreKBC/3nVxHeYIjeZw97Fn2DrEa1UehqIrRErZH+34Q8gNG+9A/MrnZJe1c poLg== 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:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=aX38mKathL6hGZ5wfaJ4tWyTc6Mqm9Kf3jmqSU2okVY=; b=ntahr3GQadTpIejNJNe8pMiReScc/yz0CYicrJDC9+0jgYnAKJhPZYLrddetfY/8kN yPRrmg9Urt2YXT0vun0a3Bu/579z7dU68aF1EJKME2E9JHtKY2P2UqaPBYkKBKSaLn3q 4lXZ6xtBuQ3ZkqQ9N9jz0Y5TmhPImKqZtmFrak6cLa/W2lD6bHe07wzFlPY6RmIdkgYJ Qi9DIYDqDBQF2dftYiUoKVTs5KApLd2mGcIOBow92AfEqGnuxuh+D28SjrwhLCF4uyvo iTN6ik/OMu0ILNTg5M9/Ird9hsExPF3UgCSZN7c/d0bHBgjp4XEKQlZCLeUaYEEPWhXn 51Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=CYId0mdd; 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 oz6si6696766ejb.124.2019.10.07.05.37.11; Mon, 07 Oct 2019 05:37:34 -0700 (PDT) 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; dkim=pass header.i=@lca.pw header.s=google header.b=CYId0mdd; 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 S1727793AbfJGMeP (ORCPT + 99 others); Mon, 7 Oct 2019 08:34:15 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:46508 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727511AbfJGMeP (ORCPT ); Mon, 7 Oct 2019 08:34:15 -0400 Received: by mail-qk1-f194.google.com with SMTP id 201so12307360qkd.13 for ; Mon, 07 Oct 2019 05:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=aX38mKathL6hGZ5wfaJ4tWyTc6Mqm9Kf3jmqSU2okVY=; b=CYId0mddJCKrzR+XxA8vZFoMDfRmBJN4cg6/EGWNPs1i+kPhJ/sX9AzAmx3RLkeXzB 8YcNqrXJS8EkuxWD+8NwJfLHk7DoxzE6+l3omsx7SkSouFC8IPFuhuEjC9xxPjWYAsAt mo7W+yyA9a/kzO6m3VSFgP1Z2lPwPhhGohSfyc1SOVlgd0HrWUJLp2ANkUgrYEOty3JM T0E5FJG5/dt6rlidSPEWKwgYcbYlF6ldGlqEfKHq0V5zR1stftyQT25Pkzmt/PSwGqt/ iNUZ+ngQ8MBGrO9ttUTELD7J5VxNRu9jBeuAP9YrCvUNpmTvmVrmt5TfVurPLTuEIrDE WUQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=aX38mKathL6hGZ5wfaJ4tWyTc6Mqm9Kf3jmqSU2okVY=; b=p2B0Sd1lK2JFa/6lQ6EIbIKsVO1dovcQIIgXFrVuhs5HE2WG0xEsvTOGtcWSuyDeMA nUpyAr9hpx/3qXLEzH3YfrATIuvXvYxvD/+p06M+TyuzmN5/XBf8OU8BpADPz1utK3qG s80oGC069gnYZSFNtl8+KASPbhD2vtyu8VY2E7K/m5ZD2bOdrHFo41mefSe6Wwt4EEmJ 02yLSAGYqff+LK25Om8ZEnW+4rY9w812i+bFWDWOfHMdVyQzeM+dmSCLk7daqrChhog+ tuCcRsRMvWzogYKGEZ0GhR6XK7PvZgvFOkNBh45gy2Asr4Lddu/aIz07smTDYu1Tsvz4 RnAQ== X-Gm-Message-State: APjAAAWMCfEZ/4WdDcT5S17WJv9Qx6M8w51JhzJSH4cnYhTMIeVUM9EB h37ygkwjLPt/8K685FXo+gLbGQ== X-Received: by 2002:ae9:ebcc:: with SMTP id b195mr21560825qkg.387.1570451654081; Mon, 07 Oct 2019 05:34:14 -0700 (PDT) Received: from dhcp-41-57.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i30sm10406440qte.27.2019.10.07.05.34.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Oct 2019 05:34:13 -0700 (PDT) Message-ID: <1570451651.5576.285.camel@lca.pw> Subject: Re: [PATCH v2] mm/page_isolation: fix a deadlock with printk() From: Qian Cai To: Petr Mladek , Michal Hocko Cc: akpm@linux-foundation.org, sergey.senozhatsky.work@gmail.com, rostedt@goodmis.org, peterz@infradead.org, david@redhat.com, john.ogness@linutronix.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 07 Oct 2019 08:34:11 -0400 In-Reply-To: <20191007090553.g5cq7qa4tj5yrtaa@pathway.suse.cz> References: <1570228005-24979-1-git-send-email-cai@lca.pw> <20191007080742.GD2381@dhcp22.suse.cz> <20191007090553.g5cq7qa4tj5yrtaa@pathway.suse.cz> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6 (3.22.6-10.el7) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-10-07 at 11:05 +0200, Petr Mladek wrote: > On Mon 2019-10-07 10:07:42, Michal Hocko wrote: > > On Fri 04-10-19 18:26:45, Qian Cai wrote: > > > It is unsafe to call printk() while zone->lock was held, i.e., > > > > > > zone->lock --> console_lock > > > > > > because the console could always allocate some memory in different code > > > paths and form locking chains in an opposite order, > > > > > > console_lock --> * --> zone->lock > > > > > > As the result, it triggers lockdep splats like below and in different > > > code paths in this thread [1]. Since has_unmovable_pages() was only used > > > in set_migratetype_isolate() and is_pageblock_removable_nolock(). Only > > > the former will set the REPORT_FAILURE flag which will call printk(). > > > Hence, unlock the zone->lock just before the dump_page() there where > > > when has_unmovable_pages() returns true, there is no need to hold the > > > lock anyway in the rest of set_migratetype_isolate(). > > > > > > While at it, remove a problematic printk() in __offline_isolated_pages() > > > only for debugging as well which will always disable lockdep on debug > > > kernels. > > > > I do not think that removing the printk is the right long term solution. > > While I do agree that removing the debugging printk __offline_isolated_pages > > does make sense because it is essentially of a very limited use, this > > doesn't really solve the underlying problem. There are likely other > > printks from zone->lock. It would be much more saner to actually > > disallow consoles to allocate any memory while printk is called from an > > atomic context. > > The current "standard" solution for these situations is to replace > the problematic printk() with printk_deferred(). It would deffer > the console handling. > > Of course, this is a whack a mole approach. The long term solution > is to deffer printk() by default. We have finally agreed on this > few weeks ago on Plumbers conference. It is going to be added > together with fully lockless log buffer hopefully soon. It will > be part of upstreaming Real-Time related code. Does this guarantee that if, lock(zone->lock) printk_deferred() unlock(zone->lock) that the locks (console_owner and console_sem) in printk_deferred() will always be processed by the unlock(zone->lock)? If it is more of timing thing where klogd wakes up, it could still end up with, zone_lock -> console_owner/console_sem that causes a deadlock.