From patchwork Wed Jun 21 10:40:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13287160 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 C9E4AEB64D7 for ; Wed, 21 Jun 2023 10:40:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 211AB8D0002; Wed, 21 Jun 2023 06:40:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C1448D0001; Wed, 21 Jun 2023 06:40:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B08F8D0002; Wed, 21 Jun 2023 06:40:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EF5958D0001 for ; Wed, 21 Jun 2023 06:40:44 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9DB5A40921 for ; Wed, 21 Jun 2023 10:40:44 +0000 (UTC) X-FDA: 80926411608.30.93EF59C Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf09.hostedemail.com (Postfix) with ESMTP id D7726140016 for ; Wed, 21 Jun 2023 10:40:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=2rrrlu8w; dkim=pass header.d=linutronix.de header.s=2020e header.b=SBtYdYrn; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf09.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687344043; 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: references:dkim-signature; bh=u6YhCjOMdrGvMm4RX0f5dPbRDhlZ/u543AWQMPF7zO8=; b=JxhmDJyJW61dD6c/8Sh/W3+O//4G4uaujEjxh/n5U4/hVfM3SC1i1EiCPKoJbfIwa/MNW5 2nK8fHKysCjxXL0PKHK7KsObYLqa5bI7P8KBaJJvOEQMVBkiVj2yGa6zOhGjTD4QaZjZx7 IGzeL1jYjU6Jor0vCAoRybcC/Ze5tNo= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=2rrrlu8w; dkim=pass header.d=linutronix.de header.s=2020e header.b=SBtYdYrn; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf09.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687344043; a=rsa-sha256; cv=none; b=KyDKt2kq4eonIlgwynhLrvkPQX0hfOu7mu0c67T2T3AsUHvFrrFAArShnmepECPGpotLko 2CfUfbIByvWYu7nfcJNwwvgsPKHE91Bwwvhf+PTVobgNpi2y7s49ycwqPNWOPRomxpItx2 jpB5c9CDJPcrQEjyZj5xWbtuw/Hsevw= Date: Wed, 21 Jun 2023 12:40:34 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1687344040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=u6YhCjOMdrGvMm4RX0f5dPbRDhlZ/u543AWQMPF7zO8=; b=2rrrlu8wPe0vBel299lDaaZI/IO1AS0t5abfrMDRoHt+azKPcUCOwVeMF557FcaqThkRCy eywOk+8fw7WY/r6bvX1mSPQVArw+vqKorhakXv0xHsQjncJq5QvdTQAqpAMGkUfu83sdEc 4kuZ747/vdyL+UYDtAr9zLjEdCjhcKQW0z/Kk3zVfgHxsOoPLgmQsI/oposEhI5VTmzGLW E7dxHE7dU9vdPLIrl0Z2MflWxvl9oTQjmSeZ1XSPApMRr850KNCORutwIJDMGOXbJc8TJq 49oHkStv59VGyOtKmS7LY99onRwuSSBn6M9PB4LilsrnHn7G/T9w0ScT+47EOw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1687344040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=u6YhCjOMdrGvMm4RX0f5dPbRDhlZ/u543AWQMPF7zO8=; b=SBtYdYrn05N4L5/JGBigzvq4+JXXUFLZWBXi8vrqsYC3CcelUVh/Q76rGLFwctoaob+gY2 vfn9WOIG42YWjxCw== From: Sebastian Andrzej Siewior To: linux-mm@kvack.org Cc: "Luis Claudio R. Goncalves" , Andrew Morton , Mel Gorman , Michal Hocko , Tetsuo Handa , Thomas Gleixner Subject: [PATCH] mm/page_alloc: Use write_seqlock_irqsave() instead write_seqlock() + local_irq_save(). Message-ID: <20230621104034.HT6QnNkQ@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline X-Rspamd-Queue-Id: D7726140016 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: fiijh9xrsu5up8niadoh6xhphhsqb4bb X-HE-Tag: 1687344042-783498 X-HE-Meta: U2FsdGVkX18SEEyhP9xj4xEa4QmBQrRviWH73T8qrvhaakYHffc5BrSXY484Cb5Ghc059VDf0Y+i3QLulEHa8ERWrJ970YrigDz+irJ37b1PkKmaXGcFkDUY4QpiOsxxcNIWtFN3dlkSN75xkiuS0qu1QrmPgZ/ip8lQhb4bNP9kynrYj3JtnYBoXqA2no+63eHd4CihFNhPozDlsTuUxgQBvu3lDXz8vdpbUPxaaWm6ZBkqChH9/rcGEqIjZetOHW2AmFugfl2/dvZcxiyfdnM8+t+dX10rd7QIke2ie9ZYEzKgCxyh5Ax1T4kTfE6nYuzDwZl73nPreTFqsKDds0acA1QqlMdcsVhiQcNyM4dRcra6qxT5gFbORAe/k8n8NQcr4f4m8y98ZiFKBTOqn3I+zfMkcGdFFJVGV12ZHKW7rLXTASk1OSB3B6KEv+DXGLVkSM/10YKGw+i5IkoCAqISG3NRRuqqn7r04B8YRNoygq33+L+UyVEiIXUa49BLeTz8bRj7lJ9ioI6JAx9JAmxnpBIVYtLLzTcx4Bt1u5nJCMfBDN3uKIZ/31pTjaSaBr6uMC6CcClpDQVW9BLSWWuGjmkzU+rJxaAqag62A5DGASHRwbxMEPrTWyWD45jnVQUWGYp7tpvAIqrvPraA4hviFmBPFL5y87U5SvldCsT9BsUidEaBCmNA7mmNJqqFoo37un68rcsF0UGtBcZXul3PVTpVAmafwzFjUTYU65nqYutI+lNDEzK8e6GaJWWomCDnk6R4OhmnuSbnDH951xMlO5WhKcJaQ6y2ueYF+ZMsc9HXl6R0Nl7DcX5wmwRnO+Gj+v9aUU6NGjxi9kgmcfr8S9XpDgvaaHfM73t1rXQb816vWFNTsgURyrbUc3+Gl6wzDGw8vZnmvvUypUCC+93nL4KBn445cndHpTorJjFlCc9uwoaak2oat3ZzRzA167RITYLIiPP2LDWbySj EMSdqq6F Lwi4ixjvVIXOjEUX0Qlm8KR8/qq8Wg+O7ehPF5EZbaCXR2/m9jEFL4YotFm4MfOKPuF8bA/9HPhd9rkIvI1u8BXKiXdw+xuM8VSJgbGsDDF0U1p8HF9eukcL29dz3ZjGwvkvgM7rPYRv+n3s= 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: __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 because the inner spinlock_t is now 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. 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 Reviewed-by: David Hildenbrand --- mm/page_alloc.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 47421bedc12b7..99b7e7d09c5c0 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5808,11 +5808,10 @@ static void __build_all_zonelists(void *data) unsigned long flags; /* - * Explicitly disable this CPU's interrupts before taking seqlock - * to prevent any IRQ handler from calling into the page allocator - * (e.g. GFP_ATOMIC) that could hit zonelist_iter_begin and livelock. + * The zonelist_update_seq must be acquired with irqsave because the + * reader can be invoked from IRQ with GFP_ATOMIC. */ - local_irq_save(flags); + write_seqlock_irqsave(&zonelist_update_seq, flags); /* * Explicitly disable this CPU's synchronous printk() before taking * seqlock to prevent any printk() from trying to hold port->lock, for @@ -5820,7 +5819,6 @@ static void __build_all_zonelists(void *data) * calling kmalloc(GFP_ATOMIC | __GFP_NOWARN) with port->lock held. */ printk_deferred_enter(); - write_seqlock(&zonelist_update_seq); #ifdef CONFIG_NUMA memset(node_load, 0, sizeof(node_load)); @@ -5857,9 +5855,8 @@ static void __build_all_zonelists(void *data) #endif } - write_sequnlock(&zonelist_update_seq); printk_deferred_exit(); - local_irq_restore(flags); + write_sequnlock_irqrestore(&zonelist_update_seq, flags); } static noinline void __init