Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp16143390rwd; Mon, 26 Jun 2023 06:22:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69KwZdTmd30hD2eqnkujoN+9SjI35B7ma5VC75TL9VKD2PfTAixgUPSRIb/+LT0w79PLA9 X-Received: by 2002:a17:902:ce8a:b0:1b6:bced:1dc2 with SMTP id f10-20020a170902ce8a00b001b6bced1dc2mr3665117plg.0.1687785766163; Mon, 26 Jun 2023 06:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687785766; cv=none; d=google.com; s=arc-20160816; b=XDxITY76igzWPepadjnT8WThe65m8SZBnSyzNfDhmlV+uUssIpzhZ+qQBoAFdfO2bg cEvZ3vNs3MCmJ4lYTFlE9cua4hr2iq6Qg9or/Y33RtcT6fq1nqefWNtDh/YY1wUu4txe QhKgBsHHrJT6Hu9rDUyP2cS73i7pk9n1Bf6rCNeT0fkHpLe1zf2XVUnsaJbCfqg/OaVD jEtmpstBzb3kxnMljAEB3lxIBIMNqjAMHT4aQvGKRLNyNPb9bGC/UaLJcRObPFRt4GQB uOxeKdtrgxwB/njB7D0bgd9TjZfNRGaqUqZsbLa33Zb/bBitGgriX3RrS1ugy1tFfa1B NF0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=GKKc5mTUlp/YZhfdUad+vrJ3xh6+Tp/YDaO6R9IN0cA=; fh=E2/Wvguqrkx2aSje5D/QP1asYmngdG4amMfNf+g5U6M=; b=lzLnZth6FfZ2gDxOgt+rOBf187F0L/6SD2VecnZzROyLMy2TPMuVq9+BzZzWgQZjF6 vhKkcrcT7IkWOrYBcI/gi7uECJqKfSq0k6epbyVtKA18Sg+dRt7bYDsCUa2EbrFuDPNH iP9BUI4+NcuglPSzKlcCLJdINeTSdQEGBk4CczDRGTDy196b1UwsK6dczqsx2nXpWChG m4bi3U/I6t3rE0mKacnCQ8LBGmTPhXgik+SND0nuBYS6T2z0jTlb1AMfKwKo3VKEGwvO O5JjnuOAXsqVBK9bdn0L/OnW3EFs0I++va+Ekq6oT1QxuNMtUrtCAFJ+R8WYxDICFYvC zGAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w2-20020a170902d70200b001ab19e023a1si4725015ply.375.2023.06.26.06.22.34; Mon, 26 Jun 2023 06:22:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230175AbjFZNPC (ORCPT + 99 others); Mon, 26 Jun 2023 09:15:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbjFZNOo (ORCPT ); Mon, 26 Jun 2023 09:14:44 -0400 Received: from outbound-smtp46.blacknight.com (outbound-smtp46.blacknight.com [46.22.136.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10DBD10A for ; Mon, 26 Jun 2023 06:14:43 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail02.blacknight.ie [81.17.254.11]) by outbound-smtp46.blacknight.com (Postfix) with ESMTPS id 43A69FABDD 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-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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