From: Johannes Weiner Date: Thu, 27 Jul 2023 16:22:24 +0000 (-0400) Subject: mm: zswap: tighten up entry invalidation X-Git-Tag: v6.6-rc1~156^2~239 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7310895779624;p=thirdparty%2Flinux.git mm: zswap: tighten up entry invalidation Removing a zswap entry from the tree is tied to an explicit operation that's supposed to drop the base reference: swap invalidation, exclusive load, duplicate store. Don't silently remove the entry on final put, but instead warn if an entry is in tree without reference. While in that diff context, convert a BUG_ON to a WARN_ON_ONCE. No need to crash on a refcount underflow. Link: https://lkml.kernel.org/r/20230727162343.1415598-3-hannes@cmpxchg.org Signed-off-by: Johannes Weiner Reviewed-by: Yosry Ahmed Cc: Barry Song Cc: Domenico Cerasuolo Cc: Nhat Pham Cc: Seth Jennings Cc: Vitaly Wool Signed-off-by: Andrew Morton --- diff --git a/mm/zswap.c b/mm/zswap.c index 93707a1799b8a..ea921b25c245b 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -417,9 +417,9 @@ static void zswap_entry_put(struct zswap_tree *tree, { int refcount = --entry->refcount; - BUG_ON(refcount < 0); + WARN_ON_ONCE(refcount < 0); if (refcount == 0) { - zswap_rb_erase(&tree->rbroot, entry); + WARN_ON_ONCE(!RB_EMPTY_NODE(&entry->rbnode)); zswap_free_entry(entry); } }