From patchwork Thu Feb 8 02:32:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13549222 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 C2D7BC4828F for ; Thu, 8 Feb 2024 02:33:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 450C36B007D; Wed, 7 Feb 2024 21:33:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4004D6B007E; Wed, 7 Feb 2024 21:33:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EF036B0080; Wed, 7 Feb 2024 21:33:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1CA5D6B007D for ; Wed, 7 Feb 2024 21:33:21 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DFB76C024B for ; Thu, 8 Feb 2024 02:33:20 +0000 (UTC) X-FDA: 81767064960.23.BA6AC54 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) by imf15.hostedemail.com (Postfix) with ESMTP id CC9CEA000E for ; Thu, 8 Feb 2024 02:33:17 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=weZui6S4; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707359598; a=rsa-sha256; cv=none; b=KTp4P+TYZJYDGBDipgVn2d0YLOzVRUwFNhgsUgFhtP8cwDfz7y2j+O2DiW64BJTZp+83NH Z6pLZtAC2v0IQ5/L53kk2p0gQhWaLWWejEbq2yiMMirxNfIPziioK2GKTbX+RpExwrY2LW mBAGe/Sw5oFQW1AlayY1N/M5HhCfV0A= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=weZui6S4; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707359598; 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=YCEnBpcFOe2C77Vjk6R5fbEVUxas4awh0L6SVKgqthY=; b=ovV293uFRwjmA4K5Hj8Y/L3VYBjTtofUgGFNEMW5yUfcUdjMZaW4Ab+9fVVRhbFeDNbBoH hDy4yigxJMidGuiQCaRwyZoe2+RsV5aSpGmgv1toVF93ZgCGDXNMcm1a/sHsNNde7eDIZi sPve39dtNjVcsUs0hSoWeX7jWd0afnU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707359594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YCEnBpcFOe2C77Vjk6R5fbEVUxas4awh0L6SVKgqthY=; b=weZui6S4T5IvHb+TGoDKMyuF0wqgoxEl+MwiUCXhxT0Byj4eY3WO+9hTkCOHADRHRPdAVB UAuJ7a1R632aAgbm3fe4L57GphGBpIK2/1FzbA8KfdBeE/MTAMk568fpswQFaDvDEjISCH VGiR5eGWY7km86874ZBREE9N2wQx8rw= From: chengming.zhou@linux.dev To: hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou , stable@vger.kernel.org Subject: [PATCH mm-hotfixes-unstable] mm/zswap: invalidate duplicate entry when !zswap_enabled Date: Thu, 8 Feb 2024 02:32:54 +0000 Message-Id: <20240208023254.3873823-1-chengming.zhou@linux.dev> In-Reply-To: <20240207154308.bc275f3e72ec1c1fd06cf5a2@linux-foundation.org> References: <20240207154308.bc275f3e72ec1c1fd06cf5a2@linux-foundation.org> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CC9CEA000E X-Stat-Signature: xhah9dr7158zbakezeo63iwoxb1pbxx3 X-HE-Tag: 1707359597-640079 X-HE-Meta: U2FsdGVkX18vhmKIjYjc2qK7ir1/Xs1Hu77ikY5KWDpCS8xabs58dTMaZm3Uq8l3hjkdwhH8UVvoWff5bYBvl0B/hg3BQX+3OCiBpXoTpuxppXfnfFAz5VwgkBNJseuR+WHV2ed4IaxB58ZLRkx21mmZNCMaVK0nQ8YNojVr+oPYFiNGJMaigiiXymIqPL2/Yj4q2XSurd/jVfZdpGEABVwr5UPdauk8+1s6NMpF8s3EAIpYW1Wgv7LraTEwLBClDjHJRFXvMioGHLxXm/UPu3jXT6klH2SPo63yf/KuW8vv/pbFiOLvP0lkWIrjdXNX6fNuKrrvLXp071oAArGpt4pmEduZWlzLPCJQLqKd3IASpMRvwG0slbxy7Fdchk34KrPnheVdN1U5xN79GsOP0WDfg19gebCeSPzIOmmyNTHolg7IhzHM+Tybm/6sEJ59m3jgEYXlgLDTNAcvyk+GQs7MfGQeZu26P8pcLzeTVaNO+CXuCvKbkQ6w0UfYbQEi+R11sACj3eP6kJhvv2+znTKBTC0zLuQc+E6JgEwkOzLi7ZqoQwefPtAaWcFiFRycywaD8yv3C4BckHhMH7+yOhkYEXPrKbuLwpmrTAMLCe1vx8C036qOh3PaFGwIhVsLp0ctBgDyPryOsYJvGqisQCWtlM9QbdJQA25p7Nw/AU+4B7dagtvTjPeD6oJcS7+QMRhSPz9VP2Pv8MYXXQK2p3fya3aus+KCw69HhWbFiQiPrhqeu0wXPgKnHn7TgM1sY7ig7zavNRJy5+Zt3CJX1MtFXIg/+zljAqB6O85780wRdngtMcdVbedFKSuFYHyapMekjdyzGLScfx4wv0RYbekPrCmUsYQOquUoRbFohRxXKvaj3hYFo0NOh5RVSlZJN/vDC86FvTLCjm2dzD35wflpZ6AQZMVf1DhDqw/Mryk= X-Bogosity: Ham, 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou 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. Fixes: 42c06a0e8ebe ("mm: kill frontswap") Cc: Signed-off-by: Chengming Zhou Acked-by: Johannes Weiner --- mm/zswap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/zswap.c b/mm/zswap.c index fe7ee2640c69..32633d0597dc 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1516,7 +1516,7 @@ bool zswap_store(struct folio *folio) if (folio_test_large(folio)) return false; - if (!zswap_enabled || !tree) + if (!tree) return false; /* @@ -1531,6 +1531,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);