FAILED: patch "[PATCH] mm/shmem: preserve allocation errors when swapping in large entries" failed to apply to 6.18-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x f4ce23b1feef16d435aa1188b6c2a637a5373ed5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From f4ce23b1feef16d435aa1188b6c2a637a5373ed5 Mon Sep 17 00:00:00 2001
From: "David Hildenbrand (Arm)" <[email protected]>
Date: Thu, 29 Oct 2026 11:43:33 +0100
Subject: [PATCH] mm/shmem: preserve allocation errors when swapping in large
entries
shmem_swapin_folio() adjusts swap to the requested slot within a large swap entry before allocating a folio. If allocation or charging fails, the error path compares this adjusted value with the original entry still stored in the XArray in shmem_confirm_swap().
Unless the index is at the start of the entry, this turns -ENOMEM into -EEXIST even though nothing changed.
The caller retries -EEXIST, so persistent allocation failures can leave the task spinning instead of returning the error.
Restore swap to index_entry on allocation failure so the existing error path checks the original entry. This preserves the allocation error if the entry is unchanged and still retries if it changed concurrently.
--- mm/shmem.c | 2 ++ 1 file changed, 2 insertions(+)
mm/shmem.c +2 -0
@@ -2552,6 +2552,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,else error = -ENOMEM ; folio =NULL ; +/* Make sure to validate the original value. */ + swap = index_entry; goto failed; }if (fault_type) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 mm/shmem: preserve allocation errors when swapping in large entries
From: "David Hildenbrand (Arm)" <[email protected]>
[ Upstream commit f4ce23b1feef16d435aa1188b6c2a637a5373ed5 ]
shmem_swapin_folio() adjusts swap to the requested slot within a large swap entry before allocating a folio. If allocation or charging fails, the error path compares this adjusted value with the original entry still stored in the XArray in shmem_confirm_swap().
Unless the index is at the start of the entry, this turns -ENOMEM into -EEXIST even though nothing changed.
The caller retries -EEXIST, so persistent allocation failures can leave the task spinning instead of returning the error.
Restore swap to index_entry on allocation failure so the existing error path checks the original entry. This preserves the allocation error if the entry is unchanged and still retries if it changed concurrently.
--- mm/shmem.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/shmem.c +4 -0
@@ -2376,6 +2376,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,if (IS_ERR (folio)) { error =PTR_ERR (folio); folio =NULL ; +/* Make sure to validate the original value. */ + swap = index_entry; goto failed; } skip_swapcache = true;
@@ -2384,6 +2386,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, folio =shmem_swapin_cluster (swap, gfp, info, index);if (!folio) { error = -ENOMEM ; +/* Make sure to validate the original value. */ + swap = index_entry; goto failed; } }
Signature · 1 line
2.53.0