From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388718; b=WywYiVKfnL00W8K7/xr5oS01fiIUcflaHRsoMN5nYCAZng+GmJECOSQ0bRZIPZIX/gs7 MHdd39/0x/YcYptbXYbkXzP4mxH0weFnviocB34wVciuABMMSg2sfKURGWacnWOVT2i9s wn7m7y+kj2PNFtZPd9xP3nhjNohh6zcAQyxjdgq+Dt5PO9SV2UmyqMyGxLpifyxGtrYKt CbWom7QrvvAPkn6FFBuhCLz7tgvRceSDuUYEnauGnw4RZU+Bj1mpmZOVRLAN6jUGyv5UH quaZoquTK5DD841QwNBUtlDQZjW0KbNniaN6tPMTYcd89JEXxKHtVopQHGGvnueSe7A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388718; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=/LpENz2u0IGfD+Xa4gc1jh79/tfWr0z+MjMKzEipS0I=; b=M/xgQ5tlARRDXs3aEmOQpGL77ZzhMvqp9Mvg6+qVdXSeg5Pjdb6nIxClcluGSUh2X2vp o+UqXAcHMgNcbzEos8PIyr46ZSZFBUaBYvdt5eI2cGeXU/2HG9zL01n35Z3IYLMv5yjEj S09XwBXBGNqPq7UYDkMqgZmV0272kJV5wEJWHYoQ77YxIsaB0htWZ7MPoZWw5eAhf9sbf WgZk4/JVNuMYijdhdj3mMqoS9ua/HJ2QCy4Z6JiN1AHBVGJQldqnqcFnve9TBjLyPHYY3 iH9M9HyGdTZhDlod8J8cst7G2Vsra8EZIkYRpowFjQmCMuKMq0l16wEu54Dc1pFXIAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EHOg+s+S; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74E42606A32D; Fri, 4 Dec 2026 12:51:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EHOg+s+S Received: by smtp.kernel.org (Postfix) with ESMTPSA id 258351F00936; Fri, 4 Dec 2026 12:51:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796388718; bh=/LpENz2u0IGfD+Xa4gc1jh79/tfWr0z+MjMKzEipS0I=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=EHOg+s+SBKt0az+kEOBGnz6criESfPP4VfaG+Y6ONmYRww+DHKsnAzrP5ucNsYEko FxuyQJsGaCOAYnKith8L4ZV7pXranHwWmzrhyYl7INnCf21M74KnHfm6zgDZ6UJ3UY FFKxhmQGuiVXKKOE4ayBuMnwVHXY8QsCKkuFzPI1JspmQtXjtCzGDf9dcolzEwzjSr YqDBvfwV3sIBFZB5o3qqTqGyoSguOlpQV9+CQBWjVc3RST1xIpem34HdYFut2hlfaV akVWd0vWlEE0MmBVygF+fLDLO8fQIOdSinGZkp8onJGWuax9fyFKvA3BYhDyi2aOmv GcldM3V1TFvuA== From: "David Hildenbrand (Arm)" Date: Fri, 04 Dec 2026 13:49:56 +0100 Subject: [PATCH v2 05/31] mm/shmem: don't pin inodes with eviction held off in the huge shrinker X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-fixes_core_3-v2-5-9aad65727632@kernel.org> References: <20261204-fixes_core_3-v2-0-9aad65727632@kernel.org> In-Reply-To: <20261204-fixes_core_3-v2-0-9aad65727632@kernel.org> To: Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , "David Hildenbrand (Arm)" , stable@vger.kernel.org, Chris Mason X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2584; i=david@kernel.org; h=from:subject:message-id; bh=BF3pPdmWUq0Ey9diP9swapiAGqwABMPgOAY2IOLuczc=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLKFtv3TN1q1c26sx7+lbyxOPT8Vajc5+r05T2P79ooVs wr3y7w411HKwiDGwSArpsgSFHzf4OXLdbXVbnzMMHNYmUCGMHBxCsBEAkMYGXpS+NoZZuYrqPf+ 1XiinmX0xvVcs8ohBz+Rcplm8c6GekaGZblfStNeV5ysk7XzftH+es/BH8fE7nN4T8qZfL2X3Ua JBwA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A shmem_unuse() disallows eviction of an inode while swapping in its pages, and shmem_evict_inode() waits until eviction is allowed again. However, swapping in folios will end up allocating memory with __GFP_FS, possibly triggering direct reclaim, where the superblock shrinkers can drop the last reference to that very inode. For example, shmem_unused_huge_shrink() takes and drops an inode reference to split large folios beyond i_size: swapoff another task ======= ============ shmem_unuse() shmem_disallow_eviction() shmem_swapin_folio() direct reclaim shmem_unused_huge_shrink() igrab() unlink(), close() iput() shmem_evict_inode() waits for eviction to be allowed Consequently, swapoff can deadlock against itself. Let's fix it by not pinning inodes whose eviction is disallowed in shmem_unused_huge_shrink(), effectively skipping them in this reclaim pass. Within shmem, shmem_unused_huge_shrink() is the only place where reclaim takes and drops a temporary reference to a shmem inode. We could also avoid the deadlock by swapping in under NOFS scope in shmem_unuse(). However, allocating a lot of folios under NOFS does not sound like the right approach. This has low urgency, as the race is hard to hit and swapoff is privileged. Fixes: af53d3e9e040 ("mm: swapoff: shmem_unuse() stop eviction without igrab()") Cc: stable@vger.kernel.org Reported-by: Chris Mason Reviewed-by: Baolin Wang Tested-by: Gregory Price (Meta) Reviewed-by: Gregory Price (Meta) Signed-off-by: David Hildenbrand (Arm) --- mm/shmem.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 58b337efe7b02..798581db29853 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -884,6 +884,16 @@ static enum lru_status shmem_unused_huge_isolate(struct list_head *item, if (!spin_trylock(&info->lock)) return LRU_SKIP; + /* + * Do not grab temporary inode references if eviction is disallowed, as + * we might later put the last remaining one and deadlock (e.g., + * swapoff). + */ + if (atomic_read(&info->stop_eviction)) { + spin_unlock(&info->lock); + return LRU_SKIP; + } + /* pin the inode */ inode = igrab(&info->vfs_inode); /* inode is about to be evicted */ -- 2.56.1