From patchwork Mon Mar 13 10:37:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13172178 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 0BA70C74A4B for ; Mon, 13 Mar 2023 10:37:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9246A6B0072; Mon, 13 Mar 2023 06:37:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AE1A6B0074; Mon, 13 Mar 2023 06:37:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 728456B0075; Mon, 13 Mar 2023 06:37:34 -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 62F976B0072 for ; Mon, 13 Mar 2023 06:37:34 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3E6091C624F for ; Mon, 13 Mar 2023 10:37:34 +0000 (UTC) X-FDA: 80563523628.12.D83C3E4 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf14.hostedemail.com (Postfix) with ESMTP id 2FD7B100018 for ; Mon, 13 Mar 2023 10:37:31 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678703852; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W+6m/J5co4iV+tD4vjXf7uQYThOT2r/sspycShPNR4A=; b=FcNdFt8aNvJO/0+KI4fOLX56d6oZ0NRyCOTLD5kUEzfE/irTrM+NuzCMTZpNJbrno1P57a NblcrVnXFsqtuPiq+6ZpNZyIsjPE+26pKZ+CHcFi1GZRA0QtChGRjJMq0e/xf16MN3OHPU erBBAhkhNFcAB/IsauSRKB4p36vrjCI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678703852; a=rsa-sha256; cv=none; b=jMnNF9pic314E4XVur3UBnsGfb2kQQ0Ya0OHyBDIPsZloLNgcsK1AHXMbiqwWJy9sfwTyu Cp0TsZs4STeG2nGCx6w9CoDuAuEFXK+17dNNdW7iC51IQlzBHRLSq6x9R7d+ZIbxB17m+P f5rbCdjC1Wbwc5PUykXgTWoInGFMd4g= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R391e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VdlJ.M3_1678703847; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VdlJ.M3_1678703847) by smtp.aliyun-inc.com; Mon, 13 Mar 2023 18:37:27 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, osalvador@suse.de, vbabka@suse.cz, william.lam@bytedance.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: compaction: fix the possible deadlock when isolating hugetlb pages Date: Mon, 13 Mar 2023 18:37:17 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: <1bc1c955b03603c4e14f56dfbbef9f637f18dbbd.1678703534.git.baolin.wang@linux.alibaba.com> References: <1bc1c955b03603c4e14f56dfbbef9f637f18dbbd.1678703534.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 X-Stat-Signature: bjuqsj1e1311qia7j8cxb7f1qzpfsnim X-Rspam-User: X-Rspamd-Queue-Id: 2FD7B100018 X-Rspamd-Server: rspam06 X-HE-Tag: 1678703851-543051 X-HE-Meta: U2FsdGVkX1+GNdlIxo4zv9BT0bxdWt68hDdz3W8f93nCbZ/XG2rHw119fVzVmehlDswmZ3FgciDu87pC5adYOYLlDTpB8ZPVAxvr6+XGUWhLhf4HYcZ2DHer8B2go9zxdrBwtXm/DclB9Fmmi8ixDn+oVjjEhcHcSB8U5jL6v0WqqzIJOCR4ouB2rMiKwqs6s7TMuAQTJPWzfB0mSy7vuHrojkXuioETNHei5wPCy1+fbhaefKIoW8Ozm6PuNG54uIemeVwUtAjDKrtsJiUVDeHmYehQXhVmOoza27d7VUGeYFChLUFv3UXVh4QhBhq+t1YON9Aw26FmXLOBp8/Z7+M5lM42H8E4WIpIcHA8EJ2nMqcKji2tQeUeW3uLvicQemlvO+94kFAZxZNGYLeHdl1hiocCFHLrakDrA0NKYN7uPZB0WZ9wT9aruLt3Bgqj4WaJ2T7VVDJVOJMC4CPdkDJ8ZWwUJIefV0xu+SLJfCRTI25zf2TMHdqNJDR+3hTZ5F+93aqju3KM1PyFIAVkPUTFC6uukSKxDQHwHR/Xdn6FwvvXvzrieiFRNfsU86zRHnXv7Z2zYVkKltp9XsGO4+QkF26oMFTrvWuPpXyBmZP+I4/D3dhVA0sxH6+yTG/VDzcZZ2GI+4pZJkhZa/CaSlLYsNbD5/GSGgpCirU4JLX3SXStECUA/7q7M8AZ+uyvq4wp0XXofQwhdlxVFb04qo9vJgVsjPHtVd4/vBtznnoFswAw6N/RsUSNW6UV8cHNx1SqRqBvb3+T0FEvTZjse0LewW2LhP37bSU8GbIKCTdu7nh/AKId3szI3iaDVVeBdXGrS+dp4zVI4zgydObM+n43TmS4Kq17+HInP26+mUIWmEtv2K3cCYrUzSFj2a6XvffdB+pPVju8k5HXX3HMyarA8c1754mxo6D70c9oqr5bfrh/bQ2eRehtJQbNDmabQif51h2vc2/ReNkA0Rh GwEycdtc P2XrGXA46af9cLQq2syghPv0agJXLpfXSk89SHbp+DYNd4JlLNV9hn7C61U+RCHB6sJ2zgFbESsxSr4Kt6WieBdAhiIMnJKf211Eg20XP2L85wzY= 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: When trying to isolate a migratable pageblock, it can contain several normal pages or several hugetlb pages (e.g. CONT-PTE 64K hugetlb on arm64) in a pageblock. That means we may hold the lru lock of a normal page to continue to isolate the next hugetlb page by isolate_or_dissolve_huge_page() in the same migratable pageblock. However in the isolate_or_dissolve_huge_page(), it may allocate a new hugetlb page and dissolve the old one by alloc_and_dissolve_hugetlb_folio() if the hugetlb's refcount is zero. That means we can still enter the direct compaction path to allocate a new hugetlb page under the current lru lock, which may cause possible deadlock. To avoid this possible deadlock, we should release the lru lock when trying to isolate a hugetbl page. Moreover it does not make sense to take the lru lock to isolate a hugetlb, which is not in the lru list. Fixes: 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages") Signed-off-by: Baolin Wang Reviewed-by: Mike Kravetz Reviewed-by: Vlastimil Babka --- mm/compaction.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index c9d9ad958e2a..ac8ff152421a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -893,6 +893,11 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, } if (PageHuge(page) && cc->alloc_contig) { + if (locked) { + unlock_page_lruvec_irqrestore(locked, flags); + locked = NULL; + } + ret = isolate_or_dissolve_huge_page(page, &cc->migratepages); /*