From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07C4260A2602 for ; Thu, 29 Oct 2026 20:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=DvLMNLKw; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PbsN8DUM DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=qltIiuXU+zlhML5RIS5IOe+lQ29Yj3eoAi87jDTJsc4=; b=DvLMNLKwc0BUCK o+nzi3f6pkkqEWXUKZvobgSLGrhWn/ev8gU41G1pu/tE+wdTAOZUMbTdGGRVM+GzeU25W/+qx3jcu BUyNqyVxeJtAOGdgisD9GP0Fdf00iCw1JoDSokjGaXciXiShoAYpp92XbZzADf28Ct8M3LvtDx5Rc fLKacIKpyfiMyTfwVVO6u285vu3OwEc7SKfrQtVAFlbouhCjFjpFeGcWVcGbzFihZ3t/GXLujMCWd 3YiXeOCC3lrslZ2lPFqJzb1g5HE8O2bYh3JOjGd4sdo9T5zOUhxph4ipV9DyJRVzkGrmwUjh5uBr4 V1cQR10KCLBXvRKMQW6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xMWrN-0000000AKr1-1aGd; Thu, 29 Oct 2026 20:36:29 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xMWrM-0000000AKqn-09kA for kexec@lists.infradead.org; Thu, 29 Oct 2026 20:36:28 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 75E3F6020F; Thu, 29 Oct 2026 20:36:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A1151F01825; Thu, 29 Oct 2026 20:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793306187; bh=qltIiuXU+zlhML5RIS5IOe+lQ29Yj3eoAi87jDTJsc4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=PbsN8DUMZHet0eiaz/YtPnbseBFjT1WXluzzZmPAiGCnwOVZOmGfKM9mh4Hhr8RQL 7YWdZwjM5Y5r6JqhpSIgRiraov8JyP5s3tVFCEdzVv5TXOjLSA1th27MnlnYUVgFgL sTC1CQ2rinSRaPVNA6+7XHDreBot/Mj62PBOaQUurFuFoTySKorBt6xAL5tvLLjPn7 mhhTElRxbidvb5VwGdMn4KiqZOXsOdHbTTmCNjbgcCnwq18newaSnJDP+nYR6R1cS6 RKvmRadHrc65MZtqR3trGpVjQPff933JBn/tkhEaQ/OjVCubDuvzFbz+wtW8t1s41u n6zXIzSEWRF7w== From: "David Hildenbrand (Arm)" Date: Thu, 29 Oct 2026 21:33:07 +0100 Subject: [PATCH v2 12/47] mm/huge_memory: fix livelock on device private folio X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261029-fixes_core-v2-12-a64ce7f83abb@kernel.org> References: <20261029-fixes_core-v2-0-a64ce7f83abb@kernel.org> In-Reply-To: <20261029-fixes_core-v2-0-a64ce7f83abb@kernel.org> To: Andrew Morton , Johannes Weiner , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kees Cook , Peter Zijlstra , Jann Horn , Pedro Falcato , Hugh Dickins , Pasha Tatashin , Pratyush Yadav , "Matthew Wilcox (Oracle)" , Jan Kara , Zi Yan , Lance Yang , Rik van Riel , Harry Yoo , Alistair Popple , Nico Pache , Ryan Roberts , Dev Jain , Usama Arif , Kiryl Shutsemau , Matthew Brost , John Hubbard , Peter Xu , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Oscar Salvador , Minchan Kim , Muchun Song , Xu Xin , Chengming Zhou , Chris Li , Kemeng Shi , Nhat Pham , Youngjun Park , Gregory Price , Joshua Hahn , Rakie Kim , Ying Huang , Jason Gunthorpe Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-cxl@vger.kernel.org, Josef Bacik , "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2251; i=david@kernel.org; h=from:subject:message-id; bh=tTSXVaSqYcMlwqAolP5RSmpCZsM2rRJpm1YXsCV5Hb0=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIer20905Lzv2PqpDmTOl4ztoqsFfh5lK3YtmudyjV+x SV2qq+mdJSyMIhxMMiKKbIEBd83ePlyXW21Gx8zzBxWJpAhDFycAjARzo0M/+y3cLez3TOs/a+7 1kfwzeSVL85PeZSotXbB1S1i9enXP1UzMhw/XBApxjFnktgLNZlCZa/Fr75NZQu/Grl5xyH1p24 +e1gA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Josef Bacik If do_huge_pmd_device_private() cannot lock the folio, it simply returns to try again on the next fault. Just like we did in commit b570f37a2ce4 ("mm: Fix a hmm_range_fault() livelock / starvation problem"), let's wait for the softleaf entry, which will drop the PTL and wait until the folio was unlocked. This is precisely what we do in do_swap_page() with device-private folios. This avoids possibly livelocking. Update softleaf_entry_wait_on_locked() documentation to clarify that device-private entries wait until the folio is unlocked. There seems to be no compelling reason to backport this to stable kernels unless we actually see problems there. Fix generated by an LLM and sent by Josef Bacik in private. Fixes: 4964099163d0 ("mm/memory/fault: add THP fault handling for zone device private pages") Signed-off-by: Josef Bacik [ david: simplify patch description, fixup softleaf_entry_wait_on_locked description] Reviewed-by: Zi Yan Reviewed-by: Lance Yang Signed-off-by: David Hildenbrand (Arm) --- mm/filemap.c | 4 ++-- mm/huge_memory.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index b04be64a5069..e85a4114d2ec 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1395,8 +1395,8 @@ static inline int folio_wait_bit_common(struct folio *folio, int bit_nr, #ifdef CONFIG_MIGRATION /** - * softleaf_entry_wait_on_locked - Wait for a migration entry or - * device_private entry to be removed. + * softleaf_entry_wait_on_locked - Wait for a migration entry to be removed + * or a device-private folio in a device-private entry to get unlocked. * @entry: migration or device_private swap entry. * @ptl: already locked ptl. This function will drop the lock. * diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 283c4bc8b927..2b31a425c7a3 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1500,7 +1500,7 @@ vm_fault_t do_huge_pmd_device_private(struct vm_fault *vmf) folio_unlock(folio); folio_put(folio); } else { - spin_unlock(ptl); + softleaf_entry_wait_on_locked(entry, ptl); } return ret; -- 2.43.0