From patchwork Sun Apr 2 10:48:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 13197370 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 E05D3C76196 for ; Sun, 2 Apr 2023 10:48:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7975E6B0071; Sun, 2 Apr 2023 06:48:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 747AF6B0074; Sun, 2 Apr 2023 06:48:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 636526B0075; Sun, 2 Apr 2023 06:48:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 556CD6B0071 for ; Sun, 2 Apr 2023 06:48:49 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 27119120135 for ; Sun, 2 Apr 2023 10:48:49 +0000 (UTC) X-FDA: 80636127978.28.11DD2BB Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by imf15.hostedemail.com (Postfix) with ESMTP id 5C254A0015 for ; Sun, 2 Apr 2023 10:48:46 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=none (imf15.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; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680432527; a=rsa-sha256; cv=none; b=gv9VWUE65hWpOOmaF7uXooMtYrOCA7VIV2C+oLrAHdOWGXRTTcX0JHjhF6l1YMvbvPlRNl FX/GRFL1gs4H9vNbu1vC1vEEgVUbvWaXJduckaiakIdKm4RErhhF/9baYOeksgEBCCp87+ qYUJqqFXyEl2R5QMtZLi2WqbMwTwrt8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=none (imf15.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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680432527; 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=x0YqLKqY4HpI7TLYbl1s2VuXkeDXFeYqLQOBk7Zz+UM=; b=fme6cyIReDArjhhjrLN+iiGepo9aIDmdHVAVhnBk5UgZsuC7QqnptM1W7TWKPXIVDvhNeR vqpeJ/oMr9nvpT+56jdjEkK10nqZU6EpQ0iQGHATRsQjgOrdHOH670pSlFHU+W/+bcyEW8 CzZFOzltRiUd/+Eu8MDuqiSHxVVZ3EA= Received: from fsav313.sakura.ne.jp (fsav313.sakura.ne.jp [153.120.85.144]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 332AmUo7099811; Sun, 2 Apr 2023 19:48:30 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav313.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav313.sakura.ne.jp); Sun, 02 Apr 2023 19:48:30 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav313.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 332AmUXt099807 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sun, 2 Apr 2023 19:48:30 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Sun, 2 Apr 2023 19:48:29 +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: don't check zonelist_update_seq from atomic allocations Content-Language: en-US To: Mel Gorman , Patrick Daly , Michal Hocko , David Hildenbrand , Andrew Morton Cc: syzkaller-bugs@googlegroups.com, =?utf-8?q?Ilpo_J=C3=A4rvinen?= , syzbot , linux-mm References: <000000000000b21f0a05e9ec310d@google.com> From: Tetsuo Handa In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 5C254A0015 X-Rspamd-Server: rspam01 X-Stat-Signature: eg51qyxse694iaic1fjhx6xmycbue671 X-HE-Tag: 1680432526-286032 X-HE-Meta: U2FsdGVkX1+lhKUQSC1IyV9MSTyC57i41RY6WTyp83CElW4BYGezRM1ut3G56RqbWVJe2xA0z9qoTkOm85FVfv/0luV6ICWQ2mYwyUKiO33NfcOxnb5frrawJfgYmkMY2fZ28f3L9lGoB2ldVQxngUMUWUcjgsru9UZaIwElLCeoDZCawSWj0HhcN2kEHQdf4kQZ5GXqTlhlwFRzbj+t/dB+5EUgX0mwtZ1DcCpBZc74ECy0Ddz7ZytXS4PNpnI82HsQe+8HTidiBVKJJ3sL0J7a7aIR5tL7p2Kyj3DA7Df1uutEaO2AyGAKJg1LhzEtxdjYcWDoWmyzlFty2YDp1IYvW09wUT7+7F9aZd9cyuYO/mIvwBshoghbu6rnnqPjnwm0OJDoO2/j48j2dFaYZUXE9psE8v+THD50DpX//jnLyZVP6APO5h8SqKauHH88Qm2cTKZdd7hJpNL5ZwOrIIafFTkbtB6HuEIIBsSHrWy88fS5EYvGDIcMxvo47XCE7z27rTPOIWKJBZSPORmHg9P37C/Llj1yI3t06SanAwbrPgNWB92rh0cO0zp9l9Onj/Lbxo9p17F90ynaS9eR8z0XPZbROsw9v23/5jIfWXjclkRE2ZT3fr+Mlrfz0B95+uwZJYLb5Wp/VWGr4T8SgTBw4tTF4da/u3Xj6yP6huKP9LaPfvg9lKKuL3qLch7k9x7dUnFmpqZvWaeMX1S5wRUEtJEnwPbVkBdkuQNs9qTZoOmHvdegN+ggYLjk7AKHFTGnvz9nxGt/iPd0WeBMZPJ7GFPIVtKGFHWm/BZ5H4qn7WvfqWrYk8bzPYlEevBtxad4RT/j5O9SudZGpZkTT2qZIzLCv4RcpRDCgSueCEfyFhJ4P2Gf5sroEe7tlizJXZXlRoLdSzBWhyN7yFTSw6JidHJPLOED8vjt8hHvgDr518L57D0olOrq5CbHuhBxog4Lk3+zgs/BqRR9kqS EJwQc1Xb aApqliM0XhxCecS/Qnze6lqjZSmKBHS6ozYWC1TfNjsXBRCIEgVRpcy4wXnfOVH0ENBv1L73DZUjkRV467uJjAKxgee1JZ4yFBqFinHvqNTiOj51U1yWcXiUBzV2h83gCAWAbuFyvxbOXlrXvsRw+DFrrlLk8uTgR+Bo70sVL/VMv1ov8HTn/dVYHcdwaySYmNn9c+H+w/ya4Y5GMs9IcKpDzI7ixhA7a2+S4R1cUETZnhXd0lo2bhPc26O9CdywVHSfzi/SrPPqCGJX6h4sGIJClPg4pzmWm9fXjb8zul93u9kBtffCs/j0JjtbYWNgR5wuHE5HJjapTd6e0m79tlvcccYpMp5g+BQ3fm5EeldmUXAp5dQwVSLbNqKapcFu5Ibf9WAWbVlQC/GHn8W0CEs1vQ1nwifuR/X9jn/TlAJBeq4n1M+Q2iHa+yFSoU1r1Mx8n0UzRaD3hkTW/XBzGY6KSUDtdHuLPHlI7eF06adgVS+D4wZAFiHSucw== 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, for zonelist_update_seq is checked while doing GFP_ATOMIC allocation. Since zonelist_update_seq is checked for avoiding unnecessary OOM kill, there is no need to check zonelist_update_seq for memory allocations which will fail without OOM kill. Therefore, let's keep locking dependency simple, by not checking zonelist_update_seq from !__GFP_DIRECT_RECLAIM allocations. Reported-by: syzbot Link: https://syzkaller.appspot.com/bug?extid=223c7461c58c58a4cb10 Fixes: 3d36424b3b58 ("mm/page_alloc: fix race condition between build_all_zonelists and page allocation") Signed-off-by: Tetsuo Handa --- mm/page_alloc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7136c36c5d01..80ef79b23865 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4759,17 +4759,17 @@ EXPORT_SYMBOL_GPL(fs_reclaim_release); */ static DEFINE_SEQLOCK(zonelist_update_seq); -static unsigned int zonelist_iter_begin(void) +static unsigned int zonelist_iter_begin(gfp_t gfp_mask) { - if (IS_ENABLED(CONFIG_MEMORY_HOTREMOVE)) + if (IS_ENABLED(CONFIG_MEMORY_HOTREMOVE) && (gfp_mask & __GFP_DIRECT_RECLAIM)) return read_seqbegin(&zonelist_update_seq); return 0; } -static unsigned int check_retry_zonelist(unsigned int seq) +static unsigned int check_retry_zonelist(unsigned int seq, gfp_t gfp_mask) { - if (IS_ENABLED(CONFIG_MEMORY_HOTREMOVE)) + if (IS_ENABLED(CONFIG_MEMORY_HOTREMOVE) && (gfp_mask & __GFP_DIRECT_RECLAIM)) return read_seqretry(&zonelist_update_seq, seq); return seq; @@ -5083,7 +5083,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, no_progress_loops = 0; compact_priority = DEF_COMPACT_PRIORITY; cpuset_mems_cookie = read_mems_allowed_begin(); - zonelist_iter_cookie = zonelist_iter_begin(); + zonelist_iter_cookie = zonelist_iter_begin(gfp_mask); /* * The fast path uses conservative alloc_flags to succeed only until @@ -5261,7 +5261,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, * a unnecessary OOM kill. */ if (check_retry_cpuset(cpuset_mems_cookie, ac) || - check_retry_zonelist(zonelist_iter_cookie)) + check_retry_zonelist(zonelist_iter_cookie, gfp_mask)) goto restart; /* Reclaim has failed us, start killing things */ @@ -5287,7 +5287,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, * a unnecessary OOM kill. */ if (check_retry_cpuset(cpuset_mems_cookie, ac) || - check_retry_zonelist(zonelist_iter_cookie)) + check_retry_zonelist(zonelist_iter_cookie, gfp_mask)) goto restart; /*