Commit e08d5f51 authored by Kemeng Shi's avatar Kemeng Shi Committed by Andrew Morton
Browse files

mm: shmem: avoid unpaired folio_unlock() in shmem_swapin_folio()

Patch series "Some random fixes and cleanup to shmem", v3.

This series contains some simple fixes and cleanup which are made during
learning shmem.  More details can be found in respective patches.


This patch (of 5):

If we get a folio from swap_cache_get_folio() successfully but encounter a
failure before the folio is locked, we will unlock the folio which was not
previously locked.

Put the folio and set it to NULL when a failure occurs before the folio is
locked to fix the issue.

Link: https://lkml.kernel.org/r/20250516170939.965736-1-shikemeng@huaweicloud.com
Link: https://lkml.kernel.org/r/20250516170939.965736-2-shikemeng@huaweicloud.com


Fixes: 05831351 ("mm: shmem: fix potential data corruption during shmem swapin")
Signed-off-by: default avatarKemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: default avatarBaolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: default avatarKairui Song <kasong@tencent.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: kernel test robot <oliver.sang@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 8e1c4961
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2335,6 +2335,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
		 */
		split_order = shmem_split_large_entry(inode, index, swap, gfp);
		if (split_order < 0) {
			folio_put(folio);
			folio = NULL;
			error = split_order;
			goto failed;
		}