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 4D25BEB64D8 for ; Thu, 22 Jun 2023 07:18:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 833158D0002; Thu, 22 Jun 2023 03:18:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E2CB8D0001; Thu, 22 Jun 2023 03:18:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AACF8D0002; Thu, 22 Jun 2023 03:18:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 584358D0001 for ; Thu, 22 Jun 2023 03:18:17 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2791D1C8BDE for ; Thu, 22 Jun 2023 07:18:17 +0000 (UTC) X-FDA: 80929530234.30.93E62F7 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf06.hostedemail.com (Postfix) with ESMTP id 3D04B18000E for ; Thu, 22 Jun 2023 07:18:14 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=TNnEvh0n; spf=pass (imf06.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687418295; 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:dkim-signature; bh=K8euT7PJIjmj2qCOia5e363xF1dancLI5rLiLGNOtw4=; b=w47hGE0rdaYhb7udKvcgRWepKKQ/knSUL1bLrEtzfAtG3MemSVZwb78ALxmLe95Wu70YmG tGJoSMJMLBn96Qcixg6iUFz5hxrZpHFR5WXcJBUK1sM83xzdgMHxAQDlTg+H06CAMfXKL1 WO8gjzQKCyZPwXVFKinIrwQFMPYIeLk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687418295; a=rsa-sha256; cv=none; b=IQC2ITilFRJS5WQpcqdOq+CPVRcjiU76WsUiDuDBcYmcvh9dTPNqZh5puu3E9R2IL+TDII GVn7/CvitPqRPav54AmrsIaMjsgpEnTDOmpoUunsf6PHSZX/+8/Z1E49y+K78jEc9yHeye p1gJ8mNT9TBo8pLwFHEwu6Lh3tftYX8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=TNnEvh0n; spf=pass (imf06.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com 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 A41A2203BF; Thu, 22 Jun 2023 07:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1687418293; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=K8euT7PJIjmj2qCOia5e363xF1dancLI5rLiLGNOtw4=; b=TNnEvh0nX8fAlOiREGSj2C88VN1gwojjjM1OcRvb5M5DWJMTyq/bXrLMTRzvPr+iQ9SZ+D 1AK0g458o1R01ZyLJu0779WYQSpmDIzNNHehHaIwkhdvrGL2vGaL3jg8a0yPbrnFdHx7K1 XQnPi0Nm3jMWypWQbIS7fTnDBG1sjpo= 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 861F5132BE; Thu, 22 Jun 2023 07:18:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ng97HrX1k2QNYQAAMHmgww (envelope-from ); Thu, 22 Jun 2023 07:18:13 +0000 Date: Thu, 22 Jun 2023 09:18:12 +0200 From: Michal Hocko To: Tetsuo Handa Cc: Sebastian Andrzej Siewior , linux-mm@kvack.org, "Luis Claudio R. Goncalves" , Andrew Morton , Mel Gorman , Thomas Gleixner , Petr Mladek Subject: Re: [PATCH] mm/page_alloc: Use write_seqlock_irqsave() instead write_seqlock() + local_irq_save(). Message-ID: References: <20230621104034.HT6QnNkQ@linutronix.de> <0e9fc992-8e05-2e63-b3b1-d8d3ce89fc16@I-love.SAKURA.ne.jp> <20230621130641.-5iueY1I@linutronix.de> <20230621143421.BgHjJklo@linutronix.de> <01031ffe-c81f-9cec-76fb-e70d548429cf@I-love.SAKURA.ne.jp> <8b6d3f39-c573-ca2b-957b-8c48c2fa68ad@I-love.SAKURA.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8b6d3f39-c573-ca2b-957b-8c48c2fa68ad@I-love.SAKURA.ne.jp> X-Rspamd-Queue-Id: 3D04B18000E X-Rspam-User: X-Stat-Signature: gau91dsugq1i9pm7qtci4prmt6bjqtch X-Rspamd-Server: rspam03 X-HE-Tag: 1687418294-272843 X-HE-Meta: U2F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4faJLC7sctaviBHwuCAjdQhbiX+O+Ij1AFCZ1SKvXij9WoYoKhEkxG1TzNAe+6A1e7qNDzrcKsg7hRJZDobNVossvY6mvccYXCGRRK/XRXx7ha 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 Thu 22-06-23 08:24:30, Tetsuo Handa wrote: > On 2023/06/21 23:50, Tetsuo Handa wrote: > > On 2023/06/21 23:34, Sebastian Andrzej Siewior wrote: > >>> Also, if local_irq_save() is hidden due to RT, what guarantees that > >>> > >>> write_seqlock_irqsave(&zonelist_update_seq, flags); > >>> <> > >>> some_timer_function() { > >>> printk(); > >>> } > >>> <> > >>> printk_deferred_enter(); > >>> > >>> does not happen because write_seqlock_irqsave() does not disable IRQ? > >> > >> I don't see how zonelist_update_seq and printk here are connected > >> without the port lock/ or memory allocation. But there are two things > >> that are different on RT which probably answer your question: > > > > It is explained as the first deadlock scenario in commit 1007843a9190 > > ("mm/page_alloc: fix potential deadlock on zonelist_update_seq seqlock"). > > We have to disable IRQ before making zonelist_update_seq.seqcount odd. > > > > Since we must replace local_irq_save() + write_seqlock() with write_seqlock_irqsave() for > CONFIG_PREEMPT_RT=y case but we must not replace local_irq_save() + write_seqlock() with > write_seqlock_irqsave() for CONFIG_PREEMPT_RT=n case, the proper fix is something like below? Now, I am confused. Why write_seqlock_irqsave is not allowed for !RT? Let me quote the changelog and he scenario 1: write_seqlock(&zonelist_update_seq); // makes zonelist_update_seq.seqcount odd // e.g. timer interrupt handler runs at this moment some_timer_func() { kmalloc(GFP_ATOMIC) { __alloc_pages_slowpath() { read_seqbegin(&zonelist_update_seq) { // spins forever because zonelist_update_seq.seqcount is odd } } } } // e.g. timer interrupt handler finishes write_sequnlock(&zonelist_update_seq); // makes zonelist_update_seq.seqcount even This is clearly impossible with write_seqlock_irqsave as interrupts are disabled before the lock is taken. -- Michal Hocko SUSE Labs