From patchwork Thu Jul 27 16:22:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13330364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ECFBC04A94 for ; Thu, 27 Jul 2023 16:23:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F19C46B007E; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC9456B0080; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D43226B0081; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9B18E6B0080 for ; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 563631A10D1 for ; Thu, 27 Jul 2023 16:23:51 +0000 (UTC) X-FDA: 81057913062.17.2B0A634 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf12.hostedemail.com (Postfix) with ESMTP id 6318E40013 for ; Thu, 27 Jul 2023 16:23:49 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=t1KwP89h; spf=pass (imf12.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.177 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690475029; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=g6xeXNZ7MmGxs9MCe+qdgeE1O4rbj13SYexzHrnrzbc=; b=2IJoYoL6IY3PfadkdVloAq0WmTUw9MmCoxVDrn1Pdy8ht24xjNIPILmFUhH3eOjz0U6bOt XEQguu9bBzfHlKdsp+5STp4TTH3AGGGbO0HTNccyoLV8LxgjYhdJTfNCiP2gpcRpEl4osG HInQhUE+aF7lUYbN0aw6RNInJ76ww9Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690475029; a=rsa-sha256; cv=none; b=JglWG0XbvCiE+yxPufeB7DuCHuc4ukdlOaP+jKm5WnR+GqeKjisiOu7w2cddibFTLbRvJx ICQgQi98DMCnEdn0UC1xfoGVD8CDABFmdJIx2QElP5o9gZsO6GVB9CJ3td43d5ZKrCtkKH 3FJH9XLkV2YKgK7QgtOhI6LUOQvabyY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=t1KwP89h; spf=pass (imf12.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.177 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-765a7768f1dso103176585a.0 for ; Thu, 27 Jul 2023 09:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1690475028; x=1691079828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g6xeXNZ7MmGxs9MCe+qdgeE1O4rbj13SYexzHrnrzbc=; b=t1KwP89hpnwg0NYhi1k1hMQB/3gQRSOWAy1zvJ7pueqsOL6lMhlnGs29bj9q3R7ed2 5TGX5AbXfBOKFrqHxQDMSSGFph1MqS/IIURzJrYtuyq5DJDNQSlPgyx6HKbsJCFrgyMs etJArP1Qo7jM62rDTvet0BjBWc9wIdYpICMtw4B6tf9ouYzlHD0s6flS1M2mtpzmsp3P Tg1utgnTtVxz7Ck+6yn7HuwnCpOeXrrLAxZP/B7IVeVZfU45bb/Ad1ZLt/8jOMuY4acP s9Ljx+sG57pZI23evKzyyIa5rmfHvAJu7nn7DIh1eF/R8VZWmTH5gwWvPzEBnh8xunF7 LIIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690475028; x=1691079828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g6xeXNZ7MmGxs9MCe+qdgeE1O4rbj13SYexzHrnrzbc=; b=QXLD1hizssBaTyGO8ZQ+ZGpBmXeJIF0yNy+Jt2pmMGm0hFrEDi6llr4T9tZqtWZXlU 5+1OHr0+ZOZCshE7SnG0hU5dVTRZda3NUzyq35fhxh+5CUsvCc8EM2/sNcIgfqLuYwsw DIumOrF1umH4pqlIaRoOa/wjZEo8/wM33VeaeUzsmDP6v6flOLZd51ZzMEZ1H86x+um+ SBihQ3ClK4WxphiPe6Sj7CYjeGaF1OzcVHbxRwnYWwIRR/W/hYr8tMxoTjEx8RSzpAQa JoH5YuthyyASEoI2pAQkKtflUkZkDL6JyN3LmWptZrkjbKkyCG5gmWDasmEazJXvodOQ WwTw== X-Gm-Message-State: ABy/qLaG75sRUo0jJ5n4e5M+fF+VE6+34SRsaCUBwKuITJ+i+056GWPr BpFKWmF1gf5VHDUNkcRTr5tuhw== X-Google-Smtp-Source: APBJJlHsm+mf07gWGmI92coTtdUdEWEsIic/VUEsa+GtEeTjX9B1tCutvPQZueF/jzY9ZsnEbTyiCA== X-Received: by 2002:a05:620a:ccf:b0:768:b0c:e4c1 with SMTP id b15-20020a05620a0ccf00b007680b0ce4c1mr434494qkj.27.1690475028555; Thu, 27 Jul 2023 09:23:48 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:ad06]) by smtp.gmail.com with ESMTPSA id p13-20020ae9f30d000000b0076816153dcdsm505827qkg.106.2023.07.27.09.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 09:23:48 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Domenico Cerasuolo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: zswap: tighten up entry invalidation Date: Thu, 27 Jul 2023 12:22:24 -0400 Message-ID: <20230727162343.1415598-3-hannes@cmpxchg.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727162343.1415598-1-hannes@cmpxchg.org> References: <20230727162343.1415598-1-hannes@cmpxchg.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6318E40013 X-Rspam-User: X-Stat-Signature: eqbqjaims6bu8gq6i1rybcfa5ehwf5dz X-Rspamd-Server: rspam03 X-HE-Tag: 1690475029-114141 X-HE-Meta: U2FsdGVkX19o6xWCQd3a6m64it9uZOpVn0B2UsRd9wlKM16BAu2YvM6JDbzGvA5ENQcJ80fwozsmu2uf5iGRUzoUMBwJpldtXts9vDAj7Mw/ur7LyLfzaMVHqNSL44RyREiHDHEktNrtYBnhano1lMzygUJU1/VcNcNdJaR2R3MK9t4u0oIpzi+0bTIdUOA5vgB4gB+Vijjki8g+elLWxOZDQeNggTq+unXnAfkiNTKd39kGoxkivmRPRgGqcYotsYm6OfE7pd0/+BVynwgl2Blg38MfKL3pxtsqZeQwRcBCWJzsgZ20SPaxVpNpwuilHtSd5cxBaxNR7X+toqZH5CRWcz1eK/H3/ALuvBE0fDgMggHn6JHTAakcnwvKfsRFIqDDkm0F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tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Signed-off-by: Johannes Weiner Reviewed-by: Yosry Ahmed --- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index e123b1c7981c..e34ac89e6098 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -402,9 +402,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); } }