From c1c85172b541c03bdda0636f6321a315b4e360d8 Mon Sep 17 00:00:00 2001 From: Rafael Aquini Date: Fri, 28 Jun 2024 12:23:42 -0400 Subject: [PATCH] mm/zswap: invalidate duplicate entry when !zswap_enabled JIRA: https://issues.redhat.com/browse/RHEL-40684 This patch is a backport of the following upstream commit: commit 678e54d4bb9a4822f8ae99690ac131c5d490cdb1 Author: Chengming Zhou Date: Thu Feb 8 02:32:54 2024 +0000 mm/zswap: invalidate duplicate entry when !zswap_enabled We have to invalidate any duplicate entry even when !zswap_enabled since zswap can be disabled anytime. If the folio store success before, then got dirtied again but zswap disabled, we won't invalidate the old duplicate entry in the zswap_store(). So later lru writeback may overwrite the new data in swapfile. Link: https://lkml.kernel.org/r/20240208023254.3873823-1-chengming.zhou@linux.dev Fixes: 42c06a0e8ebe ("mm: kill frontswap") Signed-off-by: Chengming Zhou Acked-by: Johannes Weiner Cc: Nhat Pham Cc: Yosry Ahmed Cc: Signed-off-by: Andrew Morton Signed-off-by: Rafael Aquini --- mm/zswap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/zswap.c b/mm/zswap.c index ef0c7aac73da..88235a01f1a3 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1350,7 +1350,7 @@ bool zswap_store(struct folio *folio) if (folio_test_large(folio)) return false; - if (!zswap_enabled || !tree) + if (!tree) return false; /* @@ -1365,6 +1365,10 @@ bool zswap_store(struct folio *folio) zswap_invalidate_entry(tree, dupentry); } spin_unlock(&tree->lock); + + if (!zswap_enabled) + return false; + objcg = get_obj_cgroup_from_folio(folio); if (objcg && !obj_cgroup_may_zswap(objcg)) { memcg = get_mem_cgroup_from_objcg(objcg);