From patchwork Tue Apr 4 00:37:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 13198949 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 B4243C76196 for ; Tue, 4 Apr 2023 00:37:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 167E16B0071; Mon, 3 Apr 2023 20:37:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1191D6B0075; Mon, 3 Apr 2023 20:37:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F23466B0078; Mon, 3 Apr 2023 20:37:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E4A286B0071 for ; Mon, 3 Apr 2023 20:37:42 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id ACF2A1C63A7 for ; Tue, 4 Apr 2023 00:37:42 +0000 (UTC) X-FDA: 80641845564.05.728E68D Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by imf04.hostedemail.com (Postfix) with ESMTP id 16CE940018 for ; Tue, 4 Apr 2023 00:37:39 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=none; spf=none (imf04.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680568661; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZBGvzV58Vu60cNIMdNH4QFcTYOXQu50Ozaj5QkqKINQ=; b=aUdtzTlFE/35n5p2MPwRYIioiZ6hqnKJAic7Fkr7K9QFugqNy4NHThenf7AVPTqMkmVno5 01cdIrN17hFFdBtsb1rioQFwl3SwCAyHlF6wi+b4A/0n/VeYJeBOyAHkQH/6DZLltRn6lI /Zju3IJ90t+QZGFbo0d8/XsRAVfjBN8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=none; spf=none (imf04.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680568661; a=rsa-sha256; cv=none; b=DSXYYMWv0ZiKWSmnXBogBJVQLrBJHSnUeFwapiimrqz6jedGPFU4rTI8c+FBtXfzcfblil AESBTqDsSysDDDdTF6RXl/POqGkbrVL5LosHhpJBXl48QzOGPu1wqySy1t3AcgnUWnRIHA HvDMY9wKgyIqzSQoM2ErbZVmwgD9m6c= Received: from fsav413.sakura.ne.jp (fsav413.sakura.ne.jp [133.242.250.112]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 3340bPuk090639; Tue, 4 Apr 2023 09:37:25 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav413.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav413.sakura.ne.jp); Tue, 04 Apr 2023 09:37:25 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav413.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 3340bO1Y090631 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Tue, 4 Apr 2023 09:37:24 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: <6266b161-e4c3-7d65-6590-da6cc04d93ec@I-love.SAKURA.ne.jp> Date: Tue, 4 Apr 2023 09:37:25 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: [PATCH] mm/page_alloc: fix potential deadlock on zonelist_update_seq seqlock Content-Language: en-US To: Petr Mladek , Michal Hocko , Patrick Daly , Mel Gorman , David Hildenbrand , Andrew Morton Cc: Sergey Senozhatsky , Steven Rostedt , John Ogness , syzkaller-bugs@googlegroups.com, =?utf-8?q?Ilpo_J=C3=A4rvinen?= , syzbot , linux-mm References: <000000000000b21f0a05e9ec310d@google.com> <78ff6e70-e986-1fcb-eafb-3edd5f2bceae@I-love.SAKURA.ne.jp> From: Tetsuo Handa In-Reply-To: X-Rspamd-Queue-Id: 16CE940018 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 91zsu8uo7z87tpm8czptbjicfitwawzb X-HE-Tag: 1680568659-985676 X-HE-Meta: U2FsdGVkX19Vlw08WjGkQ0VDpggjSty4E1KTBXoOExQjwvIA92zKlYCXkjmXMiW84tuW1NCoZWxKrF3yDppCP3+1eMuXiV/lqVphaImeb2gSPNQTF2lVEyfMLhigMeJLo0og+LSgOz8WQlKf/2iVlybWx53+IHYTPFpQ8MLldKiTf+VYuDn77O2VvfVlhA65TAYBfiLOZOvjUKXuQ2gOJdDIWAnrUVHiSBXCTkfcHok7nSrkbzOcH/9wjm6GvdXLfkaNW/uHKOKufU1GNUsH0Aa3mmKQiHjzXd+B1veJvYgtRlnNZqwy4uoLkoPgrAcf5S23rY1bIiQAvqTDoOlxN94yMyYJ0lH+ItY/xblhbkch6KeoqSpBDKUVn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hyytnim+Vls8ZlxWAXR7V8ZttvQksTDbj/H0DxZS4jWp8oQxUxucX7ffFQbHdFglVwf5oTs3vdPXhGxmm8JbxamISp0MbDoxtOrvKgt8pc3Elqjgp8/XAz47fcd5jCIpiAJ+CNV7UrZTdo7X3kt/puy4cQ= 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: syzbot is reporting circular locking dependency which involves zonelist_update_seq seqlock [1], for this lock is checked by memory allocation requests which do not need to be retried. We somehow need to prevent __alloc_pages_slowpath() from checking this lock. Since Petr Mladek thinks that __build_all_zonelists() can become a candidate for deferring printk() [2], let's make sure that current CPU/thread won't reach __alloc_pages_slowpath() while this lock is in use. Reported-by: syzbot Link: https://syzkaller.appspot.com/bug?extid=223c7461c58c58a4cb10 [1] Fixes: 3d36424b3b58 ("mm/page_alloc: fix race condition between build_all_zonelists and page allocation") Link: https://lkml.kernel.org/r/ZCrs+1cDqPWTDFNM@alley [2] Signed-off-by: Tetsuo Handa Cc: Michal Hocko Cc: Petr Mladek Reviewed-by: Sergey Senozhatsky --- mm/page_alloc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7136c36c5d01..64fa77b8d24a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6632,7 +6632,21 @@ static void __build_all_zonelists(void *data) int nid; int __maybe_unused cpu; pg_data_t *self = data; + unsigned long flags; + /* + * Since __alloc_pages_slowpath() spins if zonelist_update_seq.seqcount + * is odd, any memory allocation while zonelist_update_seq.seqcount is + * odd have to be avoided. + * + * Explicitly disable local irqs in order to avoid calling + * kmalloc(GFP_ATOMIC) from e.g. timer interrupt handler. + * Also, explicitly prevent printk() from synchronously waiting for + * port->lock because tty_insert_flip_string_and_push_buffer() might + * call kmalloc(GFP_ATOMIC | __GFP_NOWARN) while holding port->lock. + */ + local_irq_save(flags); + printk_deferred_enter(); write_seqlock(&zonelist_update_seq); #ifdef CONFIG_NUMA @@ -6671,6 +6685,8 @@ static void __build_all_zonelists(void *data) } write_sequnlock(&zonelist_update_seq); + printk_deferred_exit(); + local_irq_restore(flags); } static noinline void __init