From nobody Fri Dec 19 17:38:41 2025 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 22E29265CAD for ; Wed, 17 Dec 2025 07:32:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765956758; cv=none; b=DcXbDzzaDkyAHhqvHnnvEJtj/FhuuWrkvEQFzrZf0q0aIuUbXSIjgNI5ISNK4IXqBwWEtUUuablsLsQq4UR/8Rl94i5cYw6iqeBjhjduwLhivxE23D52ojqz8/MdimyyOWbZ78AWN2dKeW8y2B/0KRlf98mZJQ4hBTHdp031cLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765956758; c=relaxed/simple; bh=wdQJrAQvik1RORRRSK5agyJxG2LLdyS3lJaaV2kuLg4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YNJEzKQI9RPjUP15exK291vN+lu6f/DBXzXclWX5XK0cePlWSCS1Mb3OS7mCaPWeyvSsBU4taj/65j8jRIg3J/0IB6m+GH5t1AnnVIsLTVUnO8it6RqGE81R7/fRl+BnhoiZzFfQbEd/dP0DAToshMdVJxW5KaNzRJu3iANkBkI= 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=T5ORc/6N; arc=none smtp.client-ip=91.218.175.188 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="T5ORc/6N" 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=1765956750; 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=cYvZQgglq3AruPpCGYCizx0FTzSaTRzKdYal9LtEFnk=; b=T5ORc/6NzynyN75t5NLdbC/TN+V/CiKMrTESzw+PZr/EQRm4YPNNI9B4IDpZ3qzQYCPxeH DDkJEN4Y943MwYhsMvFQ5Auw0qsZmXdRaJ2uuvTOoQc+lWq0smWRfXT9CM0t+5XV4ls3As ABaeMLsbr7xgIQ2tXXD0YxFdDs/X3kw= 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, 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 v2 18/28] mm: zswap: prevent memory cgroup release in zswap_compress() Date: Wed, 17 Dec 2025 15:27:42 +0800 Message-ID: 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 --- mm/zswap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/zswap.c b/mm/zswap.c index 5d0f8b13a958d..b468046a90754 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -894,11 +894,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