From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC102606A32D for ; Mon, 23 Nov 2026 16:30:38 +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=E0+Q72hR Received: by kanga.kvack.org (Postfix) id 807816B05B4; Mon, 23 Nov 2026 11:30:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 791496B05B5; Mon, 23 Nov 2026 11:30:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60A946B05C6; Mon, 23 Nov 2026 11:30:37 -0500 (EST) 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 1EEAC6B05B4 for ; Mon, 23 Nov 2026 11:30:37 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6E15E1C43C9 for ; Mon, 23 Nov 2026 16:30:36 +0000 (UTC) X-FDA: 85466922072.21.136F27C Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf12.hostedemail.com (Postfix) with ESMTP id 8A7BB40009 for ; Mon, 23 Nov 2026 16:30:34 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=E0+Q72hR; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of david@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=david@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1795451434; b=5Tq0ONjDgtWTAkPSMCIebtf+htvscM66f8dzJA3CaDAbBVWT/FMUHZ8L6MK0N6gzuxliD9 iKZCzlm1UKtxPUn3wtya0qUkTmvVxG5sWXRiYFrjfdmHZZ9U9+hE0utZrcKh0ZWQmHXU8t SmD0VfIaGyHSrhlL73oJxOD6Jrw/hGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1795451434; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3Id7WGSAHR3shCUUyvffsnWFyWGcWhkwKAm9+/q7F4Y=; b=gyuHnjoVnDmyoR6vLHtjS9D6aL7n21GPF70IS/hhhCenVFMc4bagTsUqvPiexrHmkPrz74 VWBbPGx2Tp/UGYOo5CRW4LLRWaWNbDxdJm03zwJt1zznuTcg1iYb33/3sO46XJe8FjREvb mANKF/qSXpc6edfutAuE7w9nt6BAWQw= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=E0+Q72hR; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of david@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=david@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 018F96184F; Mon, 23 Nov 2026 16:30:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5D811F000C0; Mon, 23 Nov 2026 16:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795451433; bh=3Id7WGSAHR3shCUUyvffsnWFyWGcWhkwKAm9+/q7F4Y=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=E0+Q72hRW1vFotqa29WdwYokAX1DIUx5cQ2UT7hGDB5TaUbiSDhiuBmJxGTTg0eXz K4wLkEyrVQy/UE1XtVx3D0jddWDAHoe8BjSleaxedxdNtC8G1UkQMznhkiAGX0Lc2z wNluFPTHh0vx3+bfKbfVkr7K1wFCChtWWqKu60c1/9L9mfFWdOzBhHwzWZVKgUHGaV J62ArEyK1ibIr0QVgrFANexEiHwac9nZXE+LdUw4KXZngZLNYtUu97sTCNuVmxrKMR dRejsRcsTaFCZ31oA57K5nxtOagmRI726Cm2F0chUPkw09ZCpXeMZVO7xBeZEbPDYb SYbV0BbmiHeQA== Message-ID: <787a9e9e-407d-42ee-ac27-fb402323083b@kernel.org> Date: Mon, 23 Nov 2026 17:30:26 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/shmem: fix swapin livelock on a mismatched large swap cache folio To: Baolin Wang , mt4022@columbia.edu, Hugh Dickins , Andrew Morton , Kairui Song Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, tz2294@columbia.edu, Chris Li , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Youngjun Park , stable@vger.kernel.org References: <20261027-shmem-swapin-mismatch-v1-1-84e30aa3b9e5@columbia.edu> <3c61a49f-6a0d-49eb-8682-aece4e7e7226@kernel.org> <4af8b7ef-8028-4b98-ad21-5620f8b92f42@linux.alibaba.com> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqq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VFpzVvOpb1lCbhjwAV465Hy+NUSbbUiRxdzNQtLtgZzOV Zw7jxUCs4UUZLQTCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <4af8b7ef-8028-4b98-ad21-5620f8b92f42@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 8A7BB40009 X-Stat-Signature: ym8gdef6nn3o8xgm5kbqqtp9d6hqjmym X-Rspamd-Server: rspam08 X-Spam-Status: No, score=-22.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_PASS,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-HE-Tag: 1795451434-833621 X-HE-Meta: U2FsdGVkX1/ojnEXcC2yZtQYzQ9teO65az7Ib0H+sPP9iD38QLBtCkqMl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4JLYkwkeNYlQZsmeHNIaygnzpslnwbVQbEAgYwHO2R9UFnBjxPBijYXyhu/engmaj6ycJiHPZ71dz60rkDGyIfeJi+frLB8CzFBfxIpArp7/YVjQ/0gKEV6KYlw2RzPhPbi3dcfCmqAoAWJsiZEryThTSZaXsf1uqVU5SXb21Y2Hzfwr65vL5JQJvSP3c+6PWVdISRO7CWraOFU0fZhbImDgApnIdPXLfKGfXU81to+eZyk0SUdPTeYrOzZ3AHtl+UHIkxOmMnLG4o2BEv01SN8TTY34/1/zmUOQ01nmeQDbakNETWYfalkT9hLbPqab+BdMDn15pG3/yIP8SMYHeIvTbd8YyfachnNlragk321dK4r11x1F0Ubbhk8s+2YH9vQ6xkSa+42ufybAY7RcoqMNGa47uCgtYsNQmVQGO08Typ9bojvgK3MfKudAU07tEs28SXVaRe8WQVW/pzT2tLlHDn Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 11/23/26 08:18, Baolin Wang wrote: > > > On 11/19/26 7:06 AM, David Hildenbrand (Arm) wrote: >> On 10/27/26 21:33, Mani Tofigh via B4 Relay wrote: >>> From: Mani Tofigh >>> >>> On a SWP_SYNCHRONOUS_IO swap device, a large shmem folio can be left in >>> the swap cache over swap slots that another file now uses. Reading >>> that other file then loops forever in shmem_get_folio_gfp(): >>> shmem_swapin_folio() finds the large folio, rounds the index and the >>> swap entry down to the folio's size, finds no matching entry in the >>> file and returns -EEXIST, and the retry finds the same folio again. >>> Since the task keeps the mapping locked, a munmap() of the same mapping >>> waits forever. >>> >>> The folio is left behind when the slots are freed and reused while the >>> swapin is still allocating it: >>> >>> Task A (reads X) Task B >>> ---------------- ------ >>> shmem_swapin_folio() >>> allocate a large folio >>> for X's slots >>> punch a hole in X >>> /* X's slots freed */ >>> swap out file Y >>> /* Y reuses those slots */ >>> add the folio to the swap >>> cache over those slots >>> shmem_confirm_swap() fails >>> /* -EEXIST, the folio stays >>> in the swap cache */ >>> >>> Task C (reads Y) >>> ---------------- >>> shmem_swapin_folio() >>> finds the large folio >>> rounds down to its start, >>> where Y has no entry >>> /* -EEXIST, retried forever */ >>> >>> Before commit c246d236b18b ("mm/shmem: never bypass the swap cache for >>> SWP_SYNCHRONOUS_IO"), a direct swapin that failed this way freed its >>> folio instead of leaving it in the swap cache. >>> >>> do_swap_page() already drops a large swap cache folio that does not >>> fit for anonymous memory. Do the same in shmem_swapin_folio() and on >>> a -EEXIST, remove a large folio that is not >>> anonymous/dirty/under-writeback from the swap cache so that the retry >>> swaps in a folio that fits. >>> >>> The reproducer below fills a small brd swap device so that a 64K shmem >>> folio and the 4K pages of another file land in the same slots, and races >>> a read of the first file with a hole punch and a swapout of the second. >>> This bug was identified and confirmed with the help of a deterministic >>> hypervisor currently under development, but the non-deterministic C >>> reproducer can typically trigger it in the 2-4s time range. With the >>> fix, nothing is triggered after 600 seconds. >>> >>> Fixes: c246d236b18b ("mm/shmem: never bypass the swap cache for SWP_SYNCHRONOUS_IO") >>> Cc: stable@vger.kernel.org >>> Signed-off-by: Mani Tofigh >>> --- >>> Two patches in David Hildenbrand's v2 shmem fixes series are related >>> to this one. "mm/shmem: fix truncate hang in large swap entry" [1] >>> makes truncation retry -EEXIST directly, so it can also loop on such a >>> folio. "mm/shmem: preserve allocation errors when swapping in large >>> entries" [2] fixes a different -EEXIST loop, where a failed allocation >>> is reported as -EEXIST. >>> >>> [1] https://lore.kernel.org/all/20261027-fixes_shmem-v2-10-86a00952acb9@kernel.org/ >>> [2] https://lore.kernel.org/all/20261027-fixes_shmem-v2-11-86a00952acb9@kernel.org/ >>> >>> Reproducer: https://github.com/manitofigh/files/blob/main/linux-repros/shmemloop.c >>> --- >>> mm/shmem.c | 16 ++++++++++++++-- >>> 1 file changed, 14 insertions(+), 2 deletions(-) >>> >>> diff --git a/mm/shmem.c b/mm/shmem.c >>> index 13e0786436cd..f1da8432d55c 100644 >>> --- a/mm/shmem.c >>> +++ b/mm/shmem.c >>> @@ -2568,11 +2568,14 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, >>> * and swap cache folios are never partially freed. >>> */ >>> folio_lock(folio); >>> - if (!folio_matches_swap_entry(folio, swap) || >>> - shmem_confirm_swap(mapping, index, swap) < 0) { >>> + if (!folio_matches_swap_entry(folio, swap)) { >>> error = -EEXIST; >>> goto unlock; >>> } >>> + if (shmem_confirm_swap(mapping, index, swap) < 0) { >>> + error = -EEXIST; >>> + goto failed; >>> + } >>> if (!folio_test_uptodate(folio)) { >>> error = -EIO; >>> goto failed; >>> @@ -2613,6 +2616,15 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, >>> error = -EEXIST; >>> if (error == -EIO) >>> shmem_set_folio_swapin_error(inode, index, folio, swap); >>> + /* >>> + * A large folio that does not fit the mapping, e.g. because its swap >>> + * entries were freed and reused, would be found again on every retry. >>> + * Drop it from the swap cache so the retry can swap in a fitting one. >>> + */ >>> + if (error == -EEXIST && folio && folio_test_large(folio) && >>> + !folio_test_anon(folio) && !folio_test_dirty(folio) && >>> + !folio_test_writeback(folio)) >>> + swap_cache_del_folio(folio); >>> unlock: >>> if (folio) >>> folio_unlock(folio); >>> >>> --- >> >> I have an AI fix here: >> >> Author: Chris Mason >> Date: Wed Nov 11 18:44:55 2026 +0000 >> >> mm/shmem: don't drop a folio whose swap write failed >> >> If the swap write of a large shmem folio fails while a swap-in of >> another file finds that folio in the swap cache, its data can be >> silently lost. A read of the file then returns whatever the swap device >> holds. >> >> "mm/shmem: fix swapin livelock on a mismatched large swap cache folio", >> earlier in this series, lets shmem_swapin_folio() drop a large folio >> from the swap cache, if the folio does not fit the file that is swapped >> in and is neither dirty nor under writeback. A folio that does not fit >> can belong to another file, with its swap write still in flight. >> >> shmem_swapin_folio() holds the folio lock, but the code that completes a >> write does not take that lock. And a failed write sets dirty before it >> ends writeback. So the folio can look clean and written, although its >> write has failed: >> >> shmem_swapin_folio() swap_write_end(), failed write >> ==================== ============================== >> folio_test_dirty() == false >> folio_mark_dirty() >> folio_end_writeback() >> folio_test_writeback() == false >> swap_cache_del_folio() >> /* the only copy of the data */ >> >> The fix used here is to test writeback first, and dirty second. >> >> Signed-off-by: Chris Mason >> >> diff --git a/mm/shmem.c b/mm/shmem.c >> index 915b312e14175..457a502353a9a 100644 >> --- a/mm/shmem.c >> +++ b/mm/shmem.c >> @@ -2809,10 +2809,13 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, >> * A large folio that does not fit the mapping, e.g. because its swap >> * entries were freed and reused, would be found again on every retry. >> * Drop it from the swap cache so the retry can swap in a fitting one. >> + * A failed write sets dirty and then ends writeback, with no folio >> + * lock, so test writeback first. Both flags share folio->flags, so the >> + * order of the two loads holds. >> */ >> if (error == -EEXIST && folio && folio_test_large(folio) && >> - !folio_test_anon(folio) && !folio_test_dirty(folio) && >> - !folio_test_writeback(folio)) >> + !folio_test_anon(folio) && !folio_test_writeback(folio) && >> + !folio_test_dirty(folio)) >> swap_cache_del_folio(folio); >> unlock: >> if (folio) >> >> >> @Mani, can you double check if that makes sense (can we actually trigger that), and >> if so, send it out officially, with Fixes tag ? >> >> Feel free to rework the patch as you please. > > That makes sense to me. If Mani has no time, I'll take care of this fix. Yes, please! -- Cheers, David