From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65005EB64DA for ; Mon, 26 Jun 2023 13:14:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDD888D0003; Mon, 26 Jun 2023 09:14:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D8E428D0001; Mon, 26 Jun 2023 09:14:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C567D8D0003; Mon, 26 Jun 2023 09:14:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B4C258D0001 for ; Mon, 26 Jun 2023 09:14:45 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 650101C842E for ; Mon, 26 Jun 2023 13:14:45 +0000 (UTC) X-FDA: 80944943730.20.0B8DABA Received: from outbound-smtp47.blacknight.com (outbound-smtp47.blacknight.com [46.22.136.64]) by imf10.hostedemail.com (Postfix) with ESMTP id 321F9C001C for ; Mon, 26 Jun 2023 13:14:42 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.136.64 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687785283; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GKKc5mTUlp/YZhfdUad+vrJ3xh6+Tp/YDaO6R9IN0cA=; b=wjMWjkhY7T9Ivk/RmTKqcv7MO6r4ZA/CYaq+oJk9+Xo5tCOP1fPxHeDqZDgchApI1dJvdF 6hKCRH4CLwLe6rrYcSWgl3a4oK9KTeNfysQnf6kdBH8ypxVj8fTwiLghIwrF0KQWFLI3jm 3+N1PwRJf7YkMQgHiJbAmV30WPbiM9A= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.136.64 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687785283; a=rsa-sha256; cv=none; b=neRnmG+HgRVC0hv8VfEY8Dh4MDRcMkNluBaq/ThLX2YczrkiUB/shG+VvfVwIRZwvByA62 2Wn6vyDhuuw5dq4WbkVTPTc+sNQ/L03YQxmQI+ZNzfpLl5cmHmHuOnAWLBmTg+j5MoCvmV k+mxB4/V2qbMDu+EhoiYqnYQ8Gci8No= Received: from mail.blacknight.com (pemlinmail02.blacknight.ie [81.17.254.11]) by outbound-smtp47.blacknight.com (Postfix) with ESMTPS id 4063BFABCD for ; Mon, 26 Jun 2023 14:14:41 +0100 (IST) Received: (qmail 26953 invoked from network); 26 Jun 2023 13:14:41 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.21.103]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 26 Jun 2023 13:14:40 -0000 Date: Mon, 26 Jun 2023 14:14:38 +0100 From: Mel Gorman To: Sebastian Andrzej Siewior Cc: Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Luis Claudio R. Goncalves" , Andrew Morton , Boqun Feng , Ingo Molnar , John Ogness , Peter Zijlstra , Petr Mladek , Tetsuo Handa , Thomas Gleixner , Waiman Long , Will Deacon Subject: Re: [PATCH v3 2/2] mm/page_alloc: Use write_seqlock_irqsave() instead write_seqlock() + local_irq_save(). Message-ID: <20230626131438.54bupbuujbqe4b5a@techsingularity.net> References: <20230623171232.892937-1-bigeasy@linutronix.de> <20230623171232.892937-3-bigeasy@linutronix.de> <20230623201517.yw286Knb@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20230623201517.yw286Knb@linutronix.de> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 321F9C001C X-Stat-Signature: dyx84nzkaon7xy7d1k1g9a58qgnrz8nd X-HE-Tag: 1687785282-13100 X-HE-Meta: U2FsdGVkX19H8NHcl2SvsFkJzSd3/d4OVOqIIvzyttmLgLfkRnWO3ByoQutwkkQtQo46nT3NSKSNyVkqIqbK/I7+qoln4oMEd7ZWgFK2cX3OxmTeyF25QClZNV4wwUijs2KJhe9KPsEfkSK7YIfOVcQpUWZT2UQ42eomCGo9eAao01I+iUQm/Kx3DRX9hnR5VhkPdkYwUSY9Qm8LmCrz+7MWpV7d7bqha0fAWeXkMfM3JBF0/qPm2E69R9SzAOVz6cqy24DQxQNmU7rd9OqgrDfPPtQ4TptjTEREpmdpmil6cLLQsiqqT5SZzJxp2esFJ23JCZuA/73tU8GYDQvp5GY0QcVx+je/3Arep1UUWAs5G6M9F7OxujMnuQYlVwJ/8ou7jtHYTFFQTz+yu3Zjopd4PvbDU/h2CcOJ5+puEGlX62JQsalB5SHaaFHBzo/MqIgYYouBCJKi/sYUma5MMnUdsDgG9cGhE92Dw85feKEu8Q6MEL95QE901YhClPVwiFhIRWYF7qSx9fQCvYIJRwJUD121b3ECaen/9lz6SBFdN4OfsuOOUdW+VrHET9lLV0npygIJpJAj1FlU2Zp5x0cNzPsKjIzfIulR9zIvg37DrENnSbZPLXex1lmrC0LF7cHAix4ItHHpNJGIHie+4Ho2SVE0nf/BgzEPLZNCIWyZoBN2tI7UUICvqAQaBrgSm1MixWdePYWUU6fXS2963gM/GXevsDfxE4jbHVnOgTVlyIGVxL5vIDk4dDqg53yRvtlmmWLFljyPCoVaLIgBz1oT5wa/Cw29mmuhVVJcNz+qD7qrtYsXs3/w1ng5ZIlWnwpxcW6gYTgVqH65x2Vk8io0KqvDE8/I21kPM1t7L+yicDJd4u23GeCLmk0dELWYLEn1SKV/7rWvP9I5/kr7jTAbgTSjXmBVSfO4pcehagOgpLZ6qybv+/A9dY79+ZeODSWgXAOMw/tpClUuIdo ZJ/FwHCV BqG6X7V2CMJCjg+Ya5SXCNbSGkHBBAR5oUbseCuGjirH3YOjBf3jEqGdY1MWFyVk3Q5Xa+kOOvpG80LBTlGE2pkSbBO+ho8TnyUd8s6SKKeOznXm55AG/I0nb3Zol6TvywJzeNXaRViBBNPzXfVpdZYDlRFdzC/rJH/JbShM7riqAlKh3yziaqBgC4FzFSywf+Ann3fLZu1gd83EMIDjt1/WoWnrmiZYhlxusdhFXM1jfa+R3G/HD0FrmRaRnYENBEwjHhOo9MjbXc46GxNFpaoBLHmtqpns99RP1Rm/1lln6zFzUxW+/KJsvgt4/hjU7U0vY/Ycnx2BM9jgeNuMYtmzX8elAk/lP++RPcDFmbCTln0r15NvDbwxcpDnCvPHu6RDbxU84oD5BIcqt2+rdAqFkGg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Jun 23, 2023 at 10:15:17PM +0200, Sebastian Andrzej Siewior wrote: > __build_all_zonelists() acquires zonelist_update_seq by first disabling > interrupts via local_irq_save() and then acquiring the seqlock with > write_seqlock(). This is troublesome and leads to problems on > PREEMPT_RT. The problem is that the inner spinlock_t becomes a sleeping > lock on PREEMPT_RT and must not be acquired with disabled interrupts. > > The API provides write_seqlock_irqsave() which does the right thing in > one step. > printk_deferred_enter() has to be invoked in non-migrate-able context to > ensure that deferred printing is enabled and disabled on the same CPU. > This is the case after zonelist_update_seq has been acquired. > > There was discussion on the first submission that the order should be: > local_irq_disable(); > printk_deferred_enter(); > write_seqlock(); > > to avoid pitfalls like having an unaccounted printk() coming from > write_seqlock_irqsave() before printk_deferred_enter() is invoked. The > only origin of such a printk() can be a lockdep splat because the > lockdep annotation happens after the sequence count is incremented. > This is exceptional and subject to change. > > It was also pointed that PREEMPT_RT can be affected by the printk > problem since its write_seqlock_irqsave() does not really disable > interrupts. This isn't the case because PREEMPT_RT's printk > implementation differs from the mainline implementation in two important > aspects: > - Printing happens in a dedicated threads and not at during the > invocation of printk(). > - In emergency cases where synchronous printing is used, a different > driver is used which does not use tty_port::lock. > > Acquire zonelist_update_seq with write_seqlock_irqsave() and then defer > printk output. > > Fixes: 1007843a91909 ("mm/page_alloc: fix potential deadlock on zonelist_update_seq seqlock") > Signed-off-by: Sebastian Andrzej Siewior > Acked-by: Michal Hocko Acked-by: Mel Gorman -- Mel Gorman SUSE Labs