From patchwork Thu Mar 16 11:06:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13177385 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 91DF8C6FD1F for ; Thu, 16 Mar 2023 11:07:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03A4E900006; Thu, 16 Mar 2023 07:07:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2C62900002; Thu, 16 Mar 2023 07:07:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF551900006; Thu, 16 Mar 2023 07:07:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CF276900002 for ; Thu, 16 Mar 2023 07:07:02 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9B9F11A045C for ; Thu, 16 Mar 2023 11:07:02 +0000 (UTC) X-FDA: 80574484284.15.A72543A Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf11.hostedemail.com (Postfix) with ESMTP id B837B40015 for ; Thu, 16 Mar 2023 11:06:59 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 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=1678964821; 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=ajTuW8kXGv5xD4rOn8n789tZBhdCK8u+OH6D44lmjYQ=; b=6l0nqRvzq70D525fedEbA/X3Mi7xaReUu75WnqtOLmYhFPGG2qoi4ndmpt3ZV/NeCUM1JK 7GiYP48bLhi0TnbrkF1kGklwHZsMppSXx8SurvDUs7QPCD3ZVZKP44zGV5W+UKdL7qxjzg 8vL41D8sFI5NQTbmQN2WOTFUKuSmuCc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 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=1678964821; a=rsa-sha256; cv=none; b=HEdJ4sVKwIRhQBm64lWbtFwBGY5XejV9JgXPe9Nl0McTe4y2KBbCT1WWfO6nlZHlkubiSN txVDqxV2BSOBwXD+KNq8RPXVKdYU4es7h6fmFvpwSQhaYgvoCt0OpGvWJjIMyV6qaw6U+6 N1s+FpLQ8oVlijlIqEjTgTTWdPaiL4w= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R631e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0Ve-MbmV_1678964815; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Ve-MbmV_1678964815) by smtp.aliyun-inc.com; Thu, 16 Mar 2023 19:06:55 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, osalvador@suse.de, vbabka@suse.cz, william.lam@bytedance.com, mike.kravetz@oracle.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] mm: compaction: fix the possible deadlock when isolating hugetlb pages Date: Thu, 16 Mar 2023 19:06:47 +0800 Message-Id: <7ab3bffebe59fb419234a68dec1e4572a2518563.1678962352.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <73d6250a90707649cc010731aedc27f946d722ed.1678962352.git.baolin.wang@linux.alibaba.com> References: <73d6250a90707649cc010731aedc27f946d722ed.1678962352.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: jmbmbyw5atin783ohiu1wi697hknfe87 X-Rspamd-Queue-Id: B837B40015 X-HE-Tag: 1678964819-495346 X-HE-Meta: U2FsdGVkX1/KyZkcDkGwIKTFSPSFVtxadL9Bj5+YZFIjPpSU9dUbL/J8Ucv61Yq+O/b6al5gcbx13KuZGQS9r5MxBBFJbo+irJY9tVyV0egUCf0qjlRCl3BYkrY4aEbUXH2O+WDDgGhHSeR8S/7XXJFLVLPKSzk+iB/my4X2Vm0EgRcwYHqIe0KZFX7o8gthDFFLWbTSnCsjP9vpxOsaE5lzxeXjfkGGFn9DP2D7WwLbhewteMUVX2iUttZUiCo1Q7jbzxgrsv8N1oQm3ZWFoznXfLx/Wf7SjiWDB8IzY8cxqd/zkDeEgM9DO99qmVgSbeiqiahvUTaYpmjbOi54cbb6u6kJnJlJbz6BBIGbLxh6IS1vA99Rq2rESdl1YldcLpVf/lumw300BM6Yw429xJTuCPg8P2OVo7Wc600XqjbH8wbOe1/gq/k8DfnusYfDzj8bfhnPql3vItxxUiNqhEMjTB6XaBNnOXLbXhIUaa83Di5FPJdXNh6KEtU9FkJWUK9EY/M3nCg8IpmSgmJGHo9y4akWwVFQhgxTd8/8fgW3vKUYTF9obs/CowVQbS3agb73fGLPqCsuIiAw0gvIZ0J6AxraSmEJcuUZWUK5AI65rr2+zV7I//rLUd98eAGK8nSeoh5XWElsZCH++BtvhVtb93qBXBBJ1MnAElwRhcFukKe963CYm/lwM7Egz8sJ8Jc0c92vtvZCnaIyVNXOgtnyu9SZ8Q9mVtXspjPKvl/DFv/eTz6g/f4Ck3CT7aQt74ECa9Au0DAv+LRTgwzopq5aWQFFpmuUxjK/rUP721ZGVfTEzdkT2Hu1QziTulC8Jl/xiML1KgeEbasEndDQnlrsD+GBJls3EsDli86HxZSyEI7H2/XDmSCXAd7ED1/EJAeuUmXCHwoOEqPjOu25l6g58gjN0E+nwpgPscuXuxB9IsY2Dxo8A4rURT4jDSdsxmiYBp7K58U4xKjm/g3 yFt3BUOZ yWDxoQ1Km9Vqis80EoItAZ6yJzuhePQvkR/a8FsDYLeq3cGuPsA65jrfsiK5Sj2IElKHpKmZkIeMe1nghsExzLvwkpz5Y8KZyBme+H+hxpl190v9fR9kezA8VU8Nw7ZKiEK/qRbQUjERhZ1I= 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: Vlastimil Babka Reviewed-by: Mike Kravetz Acked-by: Mel Gorman --- Changes from v1: - Collect reviewed tags. Thanks Mike and Vlastimil. --- mm/compaction.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 7e645cdfc2e9..3df076716691 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -894,6 +894,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); /*