Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp19275926rwd; Wed, 28 Jun 2023 07:20:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Wrrv4lYJiL9OFXbElz3o0yLNFpX7qtRId26d7YM5IKBmxLygE91AZn7cKeuhFAXa/Lfv1 X-Received: by 2002:a17:906:4fc5:b0:982:9b01:a582 with SMTP id i5-20020a1709064fc500b009829b01a582mr31210454ejw.1.1687962011505; Wed, 28 Jun 2023 07:20:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687962011; cv=none; d=google.com; s=arc-20160816; b=m3qolD+DMp5Ee2aYneNogvbYuqEGa+8L/h1IV+b81SWa5OxOlgz1yj3Pho/lSd9vko RXp+QGZtDGphlOW+ezSfXh2b8jFXi5wjcRf6nbSyoxdm2vvwKRK/6bJH4tiCHk9mwA/G qtEMwvTStipHrIPfcsODBYIG07Tf145+3j+V64R67Tp3RnzXJIMq+CVt9qjgT7Z+rQqG 4VaxJQJtnm367wxyDKMflM2Sno3BuSrGS0zvtF9Vq7EESdwqT32RIl1tLSXAYa1WxCUJ ypmlxXFVaLwyTx1gnY/TT4W1zK5/fcTalbPFfLAqDeWpJJSZIJ78ig2r9YgUPUSMuKUh lveg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UBkDkoRg0HA6vloPwRjoXM7rrbP50/wBU1LZzUkViAU=; fh=ch7GGKIBIBM+eUMMWNhxdZimjqVUZkY54lg//2tZdHQ=; b=xig3wLF6J9A5TNLlA8+7gkiWBeMYqoptKeTDULwOr28vwtX+LDMMEcqRnjU1dyjBI/ yjxDWzu7rMRH+Agqm6RwcmNq0oxIxQ4Zob9qfBJD8qs8KmicB27QQ7qcmwiiT14g1b4m L09XclMhLbGZU4Z7ZTNRHj0LGl2pDNS/v+Cs6hB9ATsLMXuk51ZCFuo2Y1palHPazyPo K44ZRRuMU/Zqr1IHxkFJj95QzjCC3uN6DS3b64GJ1IT9dgXMwOlOv2vwDyEFM7R2cHdt TnPDcBZ/XkI6J07ZEmuhh/GIgBiPle8tQoAOPIrcXiLIuxwpjiHMoeH8pKVpyHnc5G1a 0CIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=EVwkpnA3; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j12-20020a17090686cc00b00988c76f9d4bsi5194811ejy.347.2023.06.28.07.19.46; Wed, 28 Jun 2023 07:20:11 -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; dkim=pass header.i=@suse.com header.s=susede1 header.b=EVwkpnA3; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231542AbjF1N4Y (ORCPT + 99 others); Wed, 28 Jun 2023 09:56:24 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:56424 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230429AbjF1N4W (ORCPT ); Wed, 28 Jun 2023 09:56:22 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 704E61F6E6; Wed, 28 Jun 2023 13:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1687960581; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UBkDkoRg0HA6vloPwRjoXM7rrbP50/wBU1LZzUkViAU=; b=EVwkpnA3ZnBl4diVvgSAhsFc0JP4kr6t+CDom0M9DLYq1eYt8N+THhgRu+9j36T7vPKeOi LJKLNiRmMCwYTXeE2s7k5fcD2XdqTTr3tXb9JZLxdpzZVoMn6LcE+m6Kg3XmAsIUjdAX1Q mBPDBX8sXuZ+VbgdBGvJF4NcamLfP+A= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4F01C138EF; Wed, 28 Jun 2023 13:56:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id l3/3EAU8nGRSDwAAMHmgww (envelope-from ); Wed, 28 Jun 2023 13:56:21 +0000 Date: Wed, 28 Jun 2023 15:56:20 +0200 From: Michal Hocko To: Sebastian Andrzej Siewior , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Luis Claudio R. Goncalves" , Boqun Feng , Ingo Molnar , John Ogness , Mel Gorman , 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: 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230623201517.yw286Knb@linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andrew, it seems that we have a consensus on the MM side of things that this is good enough to go. I am not sure about patch 1, that is more on lockdep people but I think that this patch is good enough on this own. Can we get this patch merged into mm tree and see whether any of Tetsuo concerns pop out? On Fri 23-06-23 22:15:17, 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 > --- > v2…v3 > - Update comment as per Michal's suggestion. > > v1…v2: > - Improve commit description > > mm/page_alloc.c | 15 ++++++--------- > 1 file changed, 6 insertions(+), 9 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 47421bedc12b7..440e9af67b48d 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5808,19 +5808,17 @@ 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 > + * Also disable synchronous printk() to prevent any printk() from > + * trying to hold port->lock, for > * tty_insert_flip_string_and_push_buffer() on other CPU might be > * 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 > -- > 2.40.1 -- Michal Hocko SUSE Labs