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=1795946913; b=nJd5FDyykaAU0UT15whdjYbI5Ja832vLotNjfbUA4v/jU9jT8HG6VNf6DynHyLkGdEiP JqLpSVdtpDITbWS7Kue2sluu1KahfgXL8WXWWwZN9Ri7LynVa9w80Z0ZZEJ8eMAh6yVkl CsTjK7oJga0ziUDB18oq3+gfRvFGipX61M/gl1akGweBH8IJ6Z0pAfCzf1U3Xd6aoPSJ5 FNOqlF7N62g2leAQKf5kI7OMrPTPmz5+9bfZOQ6GTNmyVeS5btC+eg1S/uRauo81TD52E oalogFs1e5ZzcD67mi3x6aA/akSUsv5hWLsY2/5saW0jc5THHHSGRDkAcLK/gUwC0FQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795946913; 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=9TlfolG4b33U7RHUsfXdEJpMnbQ1yH33ThSBUjMHxoU=; b=DA2TRx8P/n4xdmLm+OMfsOgb8vZVMde7Qos37ruitkuUmF/QrRCfhKGqSbgXGnOMCeNA 8Wqw211ehqv5bkTkpk4jGvjVZDCJSyC+8O1yQxYDcwORPL/z/8QO0H7d7ZCWky1w5Xu1z R66A+V7BbyZTs1ow29A/BmCzZifRoqOEVPFI6wEfQlQLPhN4OO7YTlDAxl4pPrt9+F9kW vt2JTalOU4kbGoTnv231Ggo8iiHl1LILc3xO3OP1iC+xsHWZCIgqI5js6Q6ue1C2DRWUe 4WInRJw4WMlEfCm7aOWRZmjpjDP+wEFHNws4NBoFHnza0csb58fmxyyGGx/kIruq76A== 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=eMPSh0EN; 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 5C1E2606A31C; Sun, 29 Nov 2026 10:08:33 +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=eMPSh0EN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88BCF1F0089B; Sun, 29 Nov 2026 10:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795946912; bh=9TlfolG4b33U7RHUsfXdEJpMnbQ1yH33ThSBUjMHxoU=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=eMPSh0ENWd3CAzIcBNZWcfELNb87hAF0v6YX5/eefwQ430OP66skcQbWyx9SQxN1t MFxqffqUlkKQSlLPAT2w2REysaivkGN1JNf1kS+f/lSnNqXYWZaiK7v7ZjjL3siNND qh42Kh3f817xY44QxEZyw+EHtos+WousHC1wp2JZMy+40IAJbe+//oN83+ndhhPbT7 m5afzDUWCwwrSrzwZ542Qo/uBx94eXItzKcskOnIFdhAGPwulOe5nvwfHwCeRLdwJ0 yqznFxpQ2eJ+DA7Liwp9pajJO9rwfdzlbkf6ZoZLz2LCVtyjVMUfumrnWkfw3jpoXW h/r7iBnK+hmeQ== From: "David Hildenbrand (Arm)" Date: Sun, 29 Nov 2026 11:06:36 +0100 Subject: [PATCH 05/32] mm/shmem: don't pin inodes with eviction held off in the huge shrinker X-Mailing-List: linux-kernel@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: <20261129-fixes_core_3-v1-5-f66094116801@kernel.org> References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> In-Reply-To: <20261129-fixes_core_3-v1-0-f66094116801@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=2418; i=david@kernel.org; h=from:subject:message-id; bh=5zZ9d/bAjNDgFGcU6Ep+YG5G5jjv8sUUdCpEjeAF2YE=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLK5f2rvv7PyacDyvdP0mvdm3fj6fLvGovMBTmVz1ja0X RFcfjVta0cpC4MYB4OsmCJLUPB9g5cv19VWu/Exw8xhZQIZwsDFKQATiXJkZDhut/LeTk8BNpH0 Aw97tjDniPPd/cfWFXD3fDPnLv1o9jcMf4XWW5lNnqC1VeGgq06N+6U5N1o/Vx65lmL5/OCtbb1 9M9kA 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 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 0bdbbdcac4aee..eb224ee26c685 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -883,6 +883,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