From nobody Mon Feb 9 14:16:37 2026 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 380EA396B66 for ; Wed, 14 Jan 2026 11:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768390494; cv=none; b=CtLjN9iddSBdCj5TpBFRc1vWxsLmgvXEfiwoOvTbPMiSqN0a8Q+tQHwW32a3Ej1zjvMkKTzqeX5v46bJCgIsagV3XetB9DylS67iJ3AV1M+OREmqX+9KZHwIZXBNQeKtBgkBRxdCCsXIaHA0lZ/ZBzxHwscnV/+tF/Kt3Kk2T3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768390494; c=relaxed/simple; bh=woWq8Dm0jueluZ7aNqvePpFM/PGAR03m/bOaA4AlNfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ReExI0znb62KzqQIQ1/ikIY5CQgpjtGD3VdSDV/770+J9wLCh+z8W7P2oYOowlL2cM8WgIJaHNlqxaGXyUGKCV4aOf5AWHjFELD4aOtwN8TDmIqg+Q20AD5H2L/VuznL8s2d002dmHjGmX/DlHrHQ9i/LSpKqFvEAkOmRulyfEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=LvLhdk0U; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="LvLhdk0U" 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=1768390491; 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=MWUbb2PaVbUJH475DQjZe6rbHPDEA+XsOVjT/pIzyrg=; b=LvLhdk0UApVUyxUSypnJIgJrYQ6X2IGJW+uU7OMEp1p35yOrmvZWgmAHbYfFk6DzD46EDz cwzGgQ1xZPkamMR256J5q//zc+X0r39cFT/v1cwDkcMkoOdyE6G1hFz6bLP0YLOayOkXaW omE7DlXRwzBCLg/I/OP5LO3r8Um5ONg= From: Qi Zheng To: hannes@cmpxchg.org, hughd@google.com, mhocko@suse.com, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, harry.yoo@oracle.com, yosry.ahmed@linux.dev, imran.f.khan@oracle.com, kamalesh.babulal@oracle.com, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, chenridong@huaweicloud.com, mkoutny@suse.com, akpm@linux-foundation.org, hamzamahfooz@linux.microsoft.com, apais@linux.microsoft.com, lance.yang@linux.dev Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Qi Zheng Subject: [PATCH v3 18/30] mm: zswap: prevent memory cgroup release in zswap_compress() Date: Wed, 14 Jan 2026 19:32:45 +0800 Message-ID: <592f65bbe05587c01a2718443a70e639cc611f3d.1768389889.git.zhengqi.arch@bytedance.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Qi Zheng In the near future, a folio will no longer pin its corresponding memory cgroup. To ensure safety, it will only be appropriate to hold the rcu read lock or acquire a reference to the memory cgroup returned by folio_memcg(), thereby preventing it from being released. In the current patch, the rcu read lock is employed to safeguard against the release of the memory cgroup in zswap_compress(). Signed-off-by: Qi Zheng Acked-by: Johannes Weiner Acked-by: Shakeel Butt Acked-by: Muchun Song Reviewed-by: Harry Yoo --- mm/zswap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/zswap.c b/mm/zswap.c index a3811b05ab579..cd926e1c03c92 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -892,11 +892,14 @@ static bool zswap_compress(struct page *page, struct = zswap_entry *entry, * to the active LRU list in the case. */ if (comp_ret || !dlen || dlen >=3D PAGE_SIZE) { + rcu_read_lock(); if (!mem_cgroup_zswap_writeback_enabled( folio_memcg(page_folio(page)))) { + rcu_read_unlock(); comp_ret =3D comp_ret ? comp_ret : -EINVAL; goto unlock; } + rcu_read_unlock(); comp_ret =3D 0; dlen =3D PAGE_SIZE; dst =3D kmap_local_page(page); --=20 2.20.1